Search in sources :

Example 46 with HSSFSheet

use of org.apache.poi.hssf.usermodel.HSSFSheet 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 47 with HSSFSheet

use of org.apache.poi.hssf.usermodel.HSSFSheet 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 48 with HSSFSheet

use of org.apache.poi.hssf.usermodel.HSSFSheet 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)

Example 49 with HSSFSheet

use of org.apache.poi.hssf.usermodel.HSSFSheet in project poi by apache.

the class TestCFRecordsAggregate method testCFRecordsAggregate.

public void testCFRecordsAggregate() {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet();
    List<Record> recs = new ArrayList<Record>();
    CFHeaderBase header = new CFHeaderRecord();
    CFRuleBase rule1 = CFRuleRecord.create(sheet, "7");
    CFRuleBase rule2 = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
    CFRuleBase rule3 = CFRuleRecord.create(sheet, ComparisonOperator.GE, "100", null);
    header.setNumberOfConditionalFormats(3);
    CellRangeAddress[] cellRanges = { new CellRangeAddress(0, 1, 0, 0), new CellRangeAddress(0, 1, 2, 2) };
    header.setCellRanges(cellRanges);
    recs.add(header);
    recs.add(rule1);
    recs.add(rule2);
    recs.add(rule3);
    CFRecordsAggregate record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
    // Serialize
    byte[] serializedRecord = new byte[record.getRecordSize()];
    record.serialize(0, serializedRecord);
    InputStream in = new ByteArrayInputStream(serializedRecord);
    //Parse
    recs = RecordFactory.createRecords(in);
    // Verify
    assertNotNull(recs);
    assertEquals(4, recs.size());
    header = (CFHeaderRecord) recs.get(0);
    rule1 = (CFRuleRecord) recs.get(1);
    assertNotNull(rule1);
    rule2 = (CFRuleRecord) recs.get(2);
    assertNotNull(rule2);
    rule3 = (CFRuleRecord) recs.get(3);
    assertNotNull(rule3);
    cellRanges = header.getCellRanges();
    assertEquals(2, cellRanges.length);
    assertEquals(3, header.getNumberOfConditionalFormats());
    assertFalse(header.getNeedRecalculation());
    record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
    record = record.cloneCFAggregate();
    assertNotNull(record.getHeader());
    assertEquals(3, record.getNumberOfRules());
    header = record.getHeader();
    rule1 = record.getRule(0);
    assertNotNull(rule1);
    rule2 = record.getRule(1);
    assertNotNull(rule2);
    rule3 = record.getRule(2);
    assertNotNull(rule3);
    cellRanges = header.getCellRanges();
    assertEquals(2, cellRanges.length);
    assertEquals(3, header.getNumberOfConditionalFormats());
    assertFalse(header.getNeedRecalculation());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CFHeaderRecord(org.apache.poi.hssf.record.CFHeaderRecord) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) CFHeaderBase(org.apache.poi.hssf.record.CFHeaderBase) CFRuleBase(org.apache.poi.hssf.record.CFRuleBase) RecordStream(org.apache.poi.hssf.model.RecordStream) ByteArrayInputStream(java.io.ByteArrayInputStream) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Record(org.apache.poi.hssf.record.Record) CFRuleRecord(org.apache.poi.hssf.record.CFRuleRecord) CFRule12Record(org.apache.poi.hssf.record.CFRule12Record) CFHeaderRecord(org.apache.poi.hssf.record.CFHeaderRecord) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 50 with HSSFSheet

use of org.apache.poi.hssf.usermodel.HSSFSheet in project poi by apache.

the class TestFeatRecord method testWithoutFeatRecord.

public void testWithoutFeatRecord() throws Exception {
    HSSFWorkbook hssf = HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls");
    InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
    assertEquals(1, hssf.getNumberOfSheets());
    int countFR = 0;
    int countFRH = 0;
    // Check on the workbook, but shouldn't be there!
    for (Record r : wb.getRecords()) {
        if (r instanceof FeatRecord) {
            countFR++;
        } else if (r.getSid() == FeatRecord.sid) {
            countFR++;
        }
        if (r instanceof FeatHdrRecord) {
            countFRH++;
        } else if (r.getSid() == FeatHdrRecord.sid) {
            countFRH++;
        }
    }
    assertEquals(0, countFR);
    assertEquals(0, countFRH);
    // Now check on the sheet
    HSSFSheet s = hssf.getSheetAt(0);
    InternalSheet sheet = HSSFTestHelper.getSheetForTest(s);
    for (RecordBase rb : sheet.getRecords()) {
        if (rb instanceof Record) {
            Record r = (Record) rb;
            if (r instanceof FeatRecord) {
                countFR++;
            } else if (r.getSid() == FeatRecord.sid) {
                countFR++;
            }
            if (r instanceof FeatHdrRecord) {
                countFRH++;
            } else if (r.getSid() == FeatHdrRecord.sid) {
                countFRH++;
            }
        }
    }
    assertEquals(0, countFR);
    assertEquals(0, countFRH);
}
Also used : InternalSheet(org.apache.poi.hssf.model.InternalSheet) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook)

Aggregations

HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)213 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)172 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)97 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)84 Test (org.junit.Test)67 FileOutputStream (java.io.FileOutputStream)34 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)27 IOException (java.io.IOException)25 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)25 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)25 File (java.io.File)21 ArrayList (java.util.ArrayList)20 HSSFPatriarch (org.apache.poi.hssf.usermodel.HSSFPatriarch)20 Row (org.apache.poi.ss.usermodel.Row)18 FileInputStream (java.io.FileInputStream)17 HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)15 OutputStream (java.io.OutputStream)14 HashMap (java.util.HashMap)14 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)13 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)12