Search in sources :

Example 81 with HSSFWorkbook

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();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 82 with HSSFWorkbook

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();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFTextbox(org.apache.poi.hssf.usermodel.HSSFTextbox) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 83 with HSSFWorkbook

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");
    }
}
Also used : HSSFPrintSetup(org.apache.poi.hssf.usermodel.HSSFPrintSetup) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) AssertionFailedError(junit.framework.AssertionFailedError) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 84 with HSSFWorkbook

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();
}
Also used : Record(org.apache.poi.hssf.record.Record) NumberRecord(org.apache.poi.hssf.record.NumberRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) TableRecord(org.apache.poi.hssf.record.TableRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 85 with HSSFWorkbook

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
    }
}
Also used : CFRuleBase(org.apache.poi.hssf.record.CFRuleBase) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)518 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)187 Test (org.junit.Test)172 Workbook (org.apache.poi.ss.usermodel.Workbook)144 Sheet (org.apache.poi.ss.usermodel.Sheet)128 Row (org.apache.poi.ss.usermodel.Row)102 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)100 Cell (org.apache.poi.ss.usermodel.Cell)96 FileOutputStream (java.io.FileOutputStream)93 IOException (java.io.IOException)91 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)77 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)69 FileInputStream (java.io.FileInputStream)59 File (java.io.File)58 ArrayList (java.util.ArrayList)52 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)38 InputStream (java.io.InputStream)28 OutputStream (java.io.OutputStream)28 CellStyle (org.apache.poi.ss.usermodel.CellStyle)28 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)26