use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestDrawingShapes method testClearShapesForPatriarch.
@Test
public void testClearShapesForPatriarch() throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet sheet = wb1.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
patriarch.createSimpleShape(new HSSFClientAnchor());
patriarch.createSimpleShape(new HSSFClientAnchor());
patriarch.createCellComment(new HSSFClientAnchor());
EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);
assertEquals(agg.getShapeToObjMapping().size(), 6);
assertEquals(agg.getTailRecords().size(), 1);
assertEquals(patriarch.getChildren().size(), 3);
patriarch.clear();
assertEquals(agg.getShapeToObjMapping().size(), 0);
assertEquals(agg.getTailRecords().size(), 0);
assertEquals(patriarch.getChildren().size(), 0);
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
sheet = wb2.getSheetAt(0);
patriarch = sheet.getDrawingPatriarch();
assertEquals(agg.getShapeToObjMapping().size(), 0);
assertEquals(agg.getTailRecords().size(), 0);
assertEquals(patriarch.getChildren().size(), 0);
wb2.close();
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestDrawingShapes method testCorrectOrderInOptRecord.
@Test
public void testCorrectOrderInOptRecord() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
EscherOptRecord opt = HSSFTestHelper.getOptRecord(textbox);
String opt1Str = opt.toXml();
textbox.setFillColor(textbox.getFillColor());
EscherContainerRecord container = HSSFTestHelper.getEscherContainer(textbox);
EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
assertEquals(opt1Str, optRecord.toXml());
textbox.setLineStyle(textbox.getLineStyle());
assertEquals(opt1Str, optRecord.toXml());
textbox.setLineWidth(textbox.getLineWidth());
assertEquals(opt1Str, optRecord.toXml());
textbox.setLineStyleColor(textbox.getLineStyleColor());
assertEquals(opt1Str, optRecord.toXml());
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestPageSettingsBlock method testPrintSetup_bug46548.
public void testPrintSetup_bug46548() {
// PageSettingBlock in this file contains PLS (sid=x004D) record
// followed by ContinueRecord (sid=x003C)
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex46548-23133.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFPrintSetup ps = sheet.getPrintSetup();
try {
ps.getCopies();
} catch (NullPointerException e) {
e.printStackTrace();
throw new AssertionFailedError("Identified bug 46548: PageSettingBlock missing PrintSetupRecord record");
}
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestRowRecordsAggregate method testArraysAndTables.
/**
* Prior to Aug 2008, POI would re-serialize spreadsheets with {@link ArrayRecord}s or
* {@link TableRecord}s with those records out of order. Similar to
* {@link SharedFormulaRecord}s, these records should appear immediately after the first
* {@link FormulaRecord}s that they apply to (and only once).<br/>
*/
@Test
public void testArraysAndTables() throws Exception {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testArraysAndTables.xls");
Record[] sheetRecs = RecordInspector.getRecords(wb.getSheetAt(0), 0);
int countArrayFormulas = verifySharedValues(sheetRecs, ArrayRecord.class);
assertEquals(5, countArrayFormulas);
int countTableFormulas = verifySharedValues(sheetRecs, TableRecord.class);
assertEquals(3, countTableFormulas);
// Note - SharedFormulaRecords are currently not re-serialized by POI (each is extracted
// into many non-shared formulas), but if they ever were, the same rules would apply.
int countSharedFormulas = verifySharedValues(sheetRecs, SharedFormulaRecord.class);
assertEquals(0, countSharedFormulas);
// if (false) { // set true to observe re-serialized file
// File f = new File(System.getProperty("java.io.tmpdir") + "/testArraysAndTables-out.xls");
// try {
// OutputStream os = new FileOutputStream(f);
// wb.write(os);
// os.close();
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// System.out.println("Output file to " + f.getAbsolutePath());
// }
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestCFRecordsAggregate method testCantMixTypes.
public void testCantMixTypes() {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
CellRangeAddress[] cellRanges = { new CellRangeAddress(0, 1, 0, 0), new CellRangeAddress(0, 1, 2, 2) };
CFRuleBase[] rules = { CFRuleRecord.create(sheet, "7"), CFRule12Record.create(sheet, ComparisonOperator.BETWEEN, "2", "5") };
try {
new CFRecordsAggregate(cellRanges, rules);
fail("Shouldn't be able to mix between types");
} catch (IllegalArgumentException e) {
// expected here
}
rules = new CFRuleBase[] { CFRuleRecord.create(sheet, "7") };
CFRecordsAggregate agg = new CFRecordsAggregate(cellRanges, rules);
assertTrue(agg.getHeader().getNeedRecalculation());
try {
agg.addRule(CFRule12Record.create(sheet, "7"));
fail("Shouldn't be able to mix between types");
} catch (IllegalArgumentException e) {
// expected here
}
}
Aggregations