aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2008-05-01 03:25:37 +0000
committerJosh Micich <josh@apache.org>2008-05-01 03:25:37 +0000
commit30f7413789472ffa406d2a12601979943408c66d (patch)
treef21da6bed0096d081ff12c7532aa7e91a53baf34 /src
parent15e082cd9bae4b71fc5a0705b2c58f6204305602 (diff)
downloadpoi-30f7413789472ffa406d2a12601979943408c66d.tar.gz
poi-30f7413789472ffa406d2a12601979943408c66d.zip
fixed bug 44892 - made HSSFWorkbook.getSheet(String) case insensitive
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@652426 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/documentation/content/xdocs/changes.xml1
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/hssf/model/Workbook.java6
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java8
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java20
5 files changed, 29 insertions, 7 deletions
diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml
index 2ee93cdefa..55308a758b 100644
--- a/src/documentation/content/xdocs/changes.xml
+++ b/src/documentation/content/xdocs/changes.xml
@@ -37,6 +37,7 @@
<!-- 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>
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 7a2bbf5ce7..58a560996d 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<!-- 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>
diff --git a/src/java/org/apache/poi/hssf/model/Workbook.java b/src/java/org/apache/poi/hssf/model/Workbook.java
index 8fa3010a4b..08f2263182 100644
--- a/src/java/org/apache/poi/hssf/model/Workbook.java
+++ b/src/java/org/apache/poi/hssf/model/Workbook.java
@@ -476,9 +476,9 @@ public class Workbook implements Model
}
/**
- * 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.
*/
@@ -487,7 +487,7 @@ public class Workbook implements Model
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;
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
index 30776608ba..a76cfd159b 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
@@ -600,6 +600,8 @@ public class HSSFWorkbook extends POIDocument
*
* @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)
@@ -639,9 +641,9 @@ public class HSSFWorkbook extends POIDocument
}
/**
- * 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)
@@ -652,7 +654,7 @@ public class HSSFWorkbook extends POIDocument
{
String sheetname = workbook.getSheetName(k);
- if (sheetname.equals(name))
+ if (sheetname.equalsIgnoreCase(name))
{
retval = (HSSFSheet) sheets.get(k);
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
index 3696bb940e..4c156e7b6f 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
@@ -17,6 +17,7 @@
package org.apache.poi.hssf.usermodel;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -39,7 +40,24 @@ public final class TestHSSFWorkbook extends TestCase {
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");