Fixed XSSFWorkbook#setRepeatingRowsAndColumns to tolerate sheet names with quotes, see bugzilla #47294

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@783445 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2009-06-10 18:44:53 +00:00
parent c6134f5116
commit af23e1554d
4 changed files with 19 additions and 6 deletions

View File

@ -35,6 +35,7 @@
<release version="3.5-beta7" date="2009-??-??">
</release>
<release version="3.5-beta6" date="2009-06-??">
<action dev="POI-DEVELOPERS" type="fix">47294 - Fixed XSSFWorkbook#setRepeatingRowsAndColumns to tolerate sheet names with quotes</action>
<action dev="POI-DEVELOPERS" type="fix">47309 - Fixed logic in HSSFCell.getCellComment to handle sheets with more than 65536 comments</action>
<action dev="POI-DEVELOPERS" type="fix">46776 - Added clone() method to MulBlankRecord to fix crash in Sheet.cloneSheet()</action>
<action dev="POI-DEVELOPERS" type="fix">47244 - Fixed HSSFSheet to handle missing header / footer records</action>

View File

@ -944,7 +944,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
CellReference colRef = new CellReference(sheetName, 0, startC, true, true);
CellReference colRef2 = new CellReference(sheetName, 0, endC, true, true);
String c = "'" + sheetName + "'!$" + colRef.getCellRefParts()[2] + ":$" + colRef2.getCellRefParts()[2];
String escapedName = SheetNameFormatter.format(sheetName);
String c = escapedName + "!$" + colRef.getCellRefParts()[2] + ":$" + colRef2.getCellRefParts()[2];
CellReference rowRef = new CellReference(sheetName, startR, 0, true, true);
CellReference rowRef2 = new CellReference(sheetName, endR, 0, true, true);
@ -952,7 +954,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
String r = "";
if (!rowRef.getCellRefParts()[1].equals("0") && !rowRef2.getCellRefParts()[1].equals("0")) {
r = ",'" + sheetName + "'!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1];
r = "," + escapedName + "!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1];
}
return c + r;
}

View File

@ -37,7 +37,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
// First test that setting RR&C for same sheet more than once only creates a
// single Print_Titles built-in record
XSSFWorkbook wb = getTestDataProvider().createWorkbook();
XSSFSheet sheet = wb.createSheet("FirstSheet");
XSSFSheet sheet = wb.createSheet("First Sheet");
// set repeating rows and columns twice for the first sheet
for (int i = 0; i < 2; i++) {
@ -48,7 +48,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
XSSFName nr1 = wb.getNameAt(0);
assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());
assertEquals("'First Sheet'!$A:$A,'First Sheet'!$1:$4", nr1.getRefersToFormula());
// Save and re-open
XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
@ -57,7 +57,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
nr1 = nwb.getNameAt(0);
assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());
assertEquals("'First Sheet'!$A:$A,'First Sheet'!$1:$4", nr1.getRefersToFormula());
// check that setting RR&C on a second sheet causes a new Print_Titles built-in
// name to be created
@ -68,7 +68,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
XSSFName nr2 = nwb.getNameAt(1);
assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr2.getNameName());
assertEquals("'SecondSheet'!$B:$C,'SecondSheet'!$1:$1", nr2.getRefersToFormula());
assertEquals("SecondSheet!$B:$C,SecondSheet!$1:$1", nr2.getRefersToFormula());
nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
}

View File

@ -293,6 +293,16 @@ public abstract class BaseTestWorkbook extends TestCase {
assertSame(row, cell.getRow());
}
public void testSetRepeatingRowsAnsColumns(){
Workbook wb = getTestDataProvider().createWorkbook();
Sheet sheet1 = wb.createSheet();
wb.setRepeatingRowsAndColumns(wb.getSheetIndex(sheet1), 0, 0, 0, 3);
//must handle sheets with quotas, see Bugzilla #47294
Sheet sheet2 = wb.createSheet("My' Sheet");
wb.setRepeatingRowsAndColumns(wb.getSheetIndex(sheet2), 0, 0, 0, 3);
}
/**
* Tests that all of the unicode capable string fields can be set, written and then read back
*/