ASF Bugzilla – Attachment 22069 Details for
Bug 45126
setRepeatingRowsAndColumns() generates many NameRecord items with the same name
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
20080603_trunk.diff (text/plain), 3.87 KB, created by
Gisella Bronzetti
on 2008-06-04 02:03:40 UTC
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Gisella Bronzetti
Created:
2008-06-04 02:03:40 UTC
Size:
3.87 KB
patch
obsolete
>Index: java/org/apache/poi/hssf/model/Workbook.java >=================================================================== >--- java/org/apache/poi/hssf/model/Workbook.java (revision 662901) >+++ java/org/apache/poi/hssf/model/Workbook.java (working copy) >@@ -57,6 +57,7 @@ > > public class Workbook implements Model > { >+ private static final String EXCEL_BUILT_IN_TITLES_ = "Excel_BuiltIn_Titles_"; > private static final int DEBUG = POILogger.DEBUG; > > // public static Workbook currentBook = null; >@@ -1895,24 +1896,57 @@ > */ > public NameRecord addName(NameRecord name) > { >- >- getOrCreateLinkTable().addName(name); > >+ LinkTable linkTable = getOrCreateLinkTable(); >+ if (checkNameAlreadyExists(linkTable, name)) { >+ throw new IllegalArgumentException( >+ "You are trying to assign an already existing builtname record: " >+ + name.getNameText()); >+ >+ } >+ linkTable.addName(name); >+ > return name; > } >+ >+ /** >+ * checks if the given name is already included in the given linkTable >+ * @param linkTable >+ * @param name >+ * @return >+ */ >+ private boolean checkNameAlreadyExists(LinkTable linkTable, NameRecord name) { >+ for (int i = 0; i < linkTable.getNumNames(); i++) { >+ NameRecord nameRecord = linkTable.getNameRecord(i); >+ if (nameRecord.getNameText().equals(name.getNameText())) { >+ return true; >+ } >+ } >+ return false; >+ } > > /**Generates a NameRecord to represent a built-in region > * @return a new NameRecord unless the index is invalid > */ > public NameRecord createBuiltInName(byte builtInName, int index) > { >- if (index == -1 || index+1 > Short.MAX_VALUE) >- throw new IllegalArgumentException("Index is not valid ["+index+"]"); >- >- NameRecord name = new NameRecord(builtInName, (short)(index)); >- >+ if (index == -1 || index + 1 > Short.MAX_VALUE) >+ throw new IllegalArgumentException("Index is not valid [" + index >+ + "]"); >+ >+ NameRecord name = new NameRecord(builtInName, (short) (index)); >+ String prefix = EXCEL_BUILT_IN_TITLES_ + index + " "; >+ int cont = 0; >+ while (checkNameAlreadyExists(linkTable, name)) { >+ cont++; >+ name = new NameRecord(); >+ String built_in_name = prefix + cont; >+ name.setNameText(built_in_name); >+ } >+ >+ > addName(name); >- >+ > return name; > } > >Index: testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java >=================================================================== >--- testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java (revision 662901) >+++ testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java (working copy) >@@ -394,15 +394,18 @@ > assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea); > assertEquals(reference, retrievedPrintArea); > >- String retrievedPrintArea2 = workbook.getPrintArea(1); >- assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea2); >- assertEquals(reference2, retrievedPrintArea2); >+ // TODO: the following statements are no more valid: >+ // no duplicated builtInName name in the same document; >+ >+// String retrievedPrintArea2 = workbook.getPrintArea(1); >+// assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea2); >+// assertEquals(reference2, retrievedPrintArea2); >+// >+// String retrievedPrintArea3 = workbook.getPrintArea(2); >+// assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea3); >+// assertEquals(reference3, retrievedPrintArea3); > >- String retrievedPrintArea3 = workbook.getPrintArea(2); >- assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea3); >- assertEquals(reference3, retrievedPrintArea3); > >- > } > > /**
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 45126
: 22069 |
22070
|
22153
|
22154
|
22155