<!-- Don't forget to update status.xml too! -->
<release version="3.1-beta2" date="2008-05-??">
+ <action dev="POI-DEVELOPERS" type="fix">44892 - made HSSFWorkbook.getSheet(String) case insensitive</action>
<action dev="POI-DEVELOPERS" type="fix">44886] - Correctly process PICT metafile in EscherMetafileBlip</action>
<action dev="POI-DEVELOPERS" type="fix">44893 - Correctly handle merged regions in HSSFSheet.autoSizeColumn</action>
</release>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1-beta2" date="2008-05-??">
+ <action dev="POI-DEVELOPERS" type="fix">44892 - made HSSFWorkbook.getSheet(String) case insensitive</action>
<action dev="POI-DEVELOPERS" type="fix">44886] - Correctly process PICT metafile in EscherMetafileBlip</action>
<action dev="POI-DEVELOPERS" type="fix">44893 - Correctly handle merged regions in HSSFSheet.autoSizeColumn</action>
</release>
}
/**
- * Determines whether a workbook contains the privided sheet name.
+ * Determines whether a workbook contains the provided sheet name.
*
- * @param name the name to test
+ * @param name the name to test (case insensitive match)
* @param excludeSheetIdx the sheet to exclude from the check or -1 to include all sheets in the check.
* @return true if the sheet contains the name, false otherwise.
*/
for ( int i = 0; i < boundsheets.size(); i++ )
{
BoundSheetRecord boundSheetRecord = (BoundSheetRecord) boundsheets.get( i );
- if (excludeSheetIdx != i && name.equals(boundSheetRecord.getSheetname()))
+ if (excludeSheetIdx != i && name.equalsIgnoreCase(boundSheetRecord.getSheetname()))
return true;
}
return false;
*
* @param sheetname sheetname to set for the sheet.
* @return HSSFSheet representing the new sheet.
+ * @throws IllegalArgumentException if there is already a sheet present with a case-insensitive
+ * match for the specified name.
*/
public HSSFSheet createSheet(String sheetname)
}
/**
- * Get sheet with the given name
+ * Get sheet with the given name (case insensitive match)
* @param name of the sheet
- * @return HSSFSheet with the name provided or null if it does not exist
+ * @return HSSFSheet with the name provided or <code>null</code> if it does not exist
*/
public HSSFSheet getSheet(String name)
{
String sheetname = workbook.getSheetName(k);
- if (sheetname.equals(name))
+ if (sheetname.equalsIgnoreCase(name))
{
retval = (HSSFSheet) sheets.get(k);
}
package org.apache.poi.hssf.usermodel;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
NameRecord nameRecord = b.getWorkbook().getNameRecord( 0 );
assertEquals( 3, nameRecord.getIndexToSheet() );
}
-
+
+ public void testCaseInsensitiveNames() {
+ HSSFWorkbook b = new HSSFWorkbook( );
+ HSSFSheet originalSheet = b.createSheet("Sheet1");
+ HSSFSheet fetchedSheet = b.getSheet("sheet1");
+ if(fetchedSheet == null) {
+ throw new AssertionFailedError("Identified bug 44892");
+ }
+ assertEquals(originalSheet, fetchedSheet);
+ try {
+ b.createSheet("sHeeT1");
+ fail("should have thrown exceptiuon due to duplicate sheet name");
+ } catch (IllegalArgumentException e) {
+ // expected during successful test
+ assertEquals("The workbook already contains a sheet of this name", e.getMessage());
+ }
+ }
+
public void testDuplicateNames() {
HSSFWorkbook b = new HSSFWorkbook( );
b.createSheet("Sheet1");