ASF Bugzilla – Attachment 22153 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
20080620.diff (text/plain), 4.83 KB, created by
Gisella Bronzetti
on 2008-06-20 06:10:44 UTC
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Gisella Bronzetti
Created:
2008-06-20 06:10:44 UTC
Size:
4.83 KB
patch
obsolete
>Index: java/org/apache/poi/hssf/model/Workbook.java >=================================================================== >--- java/org/apache/poi/hssf/model/Workbook.java (revision 669801) >+++ java/org/apache/poi/hssf/model/Workbook.java (working copy) >@@ -105,6 +105,8 @@ > > private static POILogger log = POILogFactory.getLogger(Workbook.class); > >+ private static final String EXCEL_REPEATING_NAME_PREFIX_ = "Excel_Name_Record_Titles_"; >+ > /** > * Creates new Workbook with no intitialization --useless right now > * @see #createWorkbook(List) >@@ -1918,28 +1920,69 @@ > */ > public NameRecord addName(NameRecord name) > { >- >- getOrCreateLinkTable().addName(name); >- >- return name; >+ LinkTable linkTable = getOrCreateLinkTable(); >+ if (checkNameAlreadyExists(linkTable, name)) { >+ throw new IllegalArgumentException( >+ "You are trying to assign a duplicated name 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) { >+ //Check to ensure no other names have the same case-insensitive name >+ for ( int i = getNumNames()-1; i >=0; i-- ) >+ { >+ NameRecord rec = getNameRecord(i); >+ if (rec != name) { >+ if (isDuplicatedNames(name, rec)) >+ return true; >+ } >+ } >+ return false; >+ } > >+ private boolean isDuplicatedNames(NameRecord firstName, NameRecord lastName) { >+ return lastName.getNameText().equalsIgnoreCase(firstName.getNameText()) && isSameSheetNames(firstName, lastName); >+ } >+ >+ private boolean isSameSheetNames(NameRecord firstName, NameRecord lastName) { >+ return lastName.getEqualsToIndexToSheet() == firstName.getEqualsToIndexToSheet(); >+ } >+ > /**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)); >- >- addName(name); >- >- return name; >- } >+ 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)); >+ >+ String prefix = EXCEL_REPEATING_NAME_PREFIX_ + index + " "; >+ int cont = 0; >+ while (checkNameAlreadyExists(linkTable, name)) { >+ cont++; >+ name = new NameRecord(); >+ String built_in_name = prefix + cont; >+ // It would be better to set a different builtInName here. It does not seem possible >+ name.setNameText(built_in_name); >+ } >+ addName(name); >+ return name; >+ } > >- > /** removes the name > * @param namenum name index > */ >Index: testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java >=================================================================== >--- testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java (revision 669801) >+++ testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java (working copy) >@@ -584,6 +584,33 @@ > fileOut.close(); > > assertTrue("file exists",file.exists()); >+ >+ // **************************************** >+ >+ String filename = System.getProperty("HSSF.testdata.path"); >+ >+ int i = 0; >+ for (int rowItem = 0; rowItem < 10; rowItem++) { >+ HSSFRow r = sheet.createRow(rowItem); >+ for (int column = 0; column < 2; column++) { >+ HSSFCell cellItem = r.createCell((short) column); >+ cellItem.setCellType(HSSFCell.CELL_TYPE_STRING); >+ cellItem.setCellValue("Some value here"); >+ if (rowItem == 2) { >+ workbook.setRepeatingRowsAndColumns(0, 0, 0, 0, 3 - 1); >+ sheet.createFreezePane(0, 3); >+ } >+ } >+ } >+ >+ for (int y = 0; y < workbook.getNumberOfNames(); y++) { >+ HSSFName nr = workbook.getNameAt(y); >+ System.out.println("name: " + nr.getNameName() + " ref: " + nr.getReference()); >+ } >+ >+ FileOutputStream fos = new FileOutputStream(filename + "/45126.xls"); >+ workbook.write(fos); >+ fos.close(); > } > >
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