Fix bug #49253 - When setting repeating rows and columns for XSSF, don't break the print settings if they were already there

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1082961 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2011-03-18 16:06:10 +00:00
parent aff049234a
commit ee6bb48894
3 changed files with 54 additions and 2 deletions

View File

@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta2" date="2011-??-??">
<action dev="poi-developers" type="fix">49253 - When setting repeating rows and columns for XSSF, don't break the print settings if they were already there</action>
<action dev="poi-developers" type="fix">49219 - ExternalNameRecord support for DDE Link entries without an operation</action>
<action dev="poi-developers" type="fix">50846 - More XSSFColor theme improvements, this time for Cell Borders</action>
<action dev="poi-developers" type="fix">50939 - ChartEndObjectRecord is supposed to have 6 bytes at the end, but handle it not</action>

View File

@ -1018,8 +1018,17 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn, startRow, endRow);
name.setRefersToFormula(reference);
XSSFPrintSetup printSetup = sheet.getPrintSetup();
printSetup.setValidSettings(false);
// If the print setup isn't currently defined, then add it
// in but without printer defaults
// If it's already there, leave it as-is!
CTWorksheet ctSheet = sheet.getCTWorksheet();
if(ctSheet.isSetPageSetup() && ctSheet.isSetPageMargins()) {
// Everything we need is already there
} else {
// Have initial ones put in place
XSSFPrintSetup printSetup = sheet.getPrintSetup();
printSetup.setValidSettings(false);
}
}
private static String getReferenceBuiltInRecord(String sheetName, int startC, int endC, int startR, int endR) {

View File

@ -892,4 +892,46 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals("Tabella1", t.getDisplayName());
assertEquals("A1:C3", t.getCTTable().getRef());
}
/**
* Setting repeating rows and columns shouldn't break
* any print settings that were there before
*/
public void test49253() throws Exception {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFWorkbook wb2 = new XSSFWorkbook();
// No print settings before repeating
XSSFSheet s1 = wb1.createSheet();
assertEquals(false, s1.getCTWorksheet().isSetPageSetup());
assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
wb1.setRepeatingRowsAndColumns(0, 2, 3, 1, 2);
assertEquals(true, s1.getCTWorksheet().isSetPageSetup());
assertEquals(true, s1.getCTWorksheet().isSetPageMargins());
XSSFPrintSetup ps1 = s1.getPrintSetup();
assertEquals(false, ps1.getValidSettings());
assertEquals(false, ps1.getLandscape());
// Had valid print settings before repeating
XSSFSheet s2 = wb2.createSheet();
XSSFPrintSetup ps2 = s2.getPrintSetup();
assertEquals(true, s2.getCTWorksheet().isSetPageSetup());
assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
ps2.setLandscape(false);
assertEquals(true, ps2.getValidSettings());
assertEquals(false, ps2.getLandscape());
wb2.setRepeatingRowsAndColumns(0, 2, 3, 1, 2);
ps2 = s2.getPrintSetup();
assertEquals(true, s2.getCTWorksheet().isSetPageSetup());
assertEquals(true, s2.getCTWorksheet().isSetPageMargins());
assertEquals(true, ps2.getValidSettings());
assertEquals(false, ps2.getLandscape());
}
}