Search in sources :

Example 61 with HSSFWorkbook

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

the class HSSFFileHandler method handleFile.

@Override
public void handleFile(InputStream stream, String path) throws Exception {
    HSSFWorkbook wb = new HSSFWorkbook(stream);
    handleWorkbook(wb);
    // TODO: some documents fail currently...
    // Note - as of Bugzilla 48036 (svn r828244, r828247) POI is capable of evaluating
    // IntersectionPtg.  However it is still not capable of parsing it.
    // So FormulaEvalTestData.xls now contains a few formulas that produce errors here.
    //HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
    //evaluator.evaluateAll();
    delegate.handlePOIDocument(wb);
// also try to see if some of the Records behave incorrectly
// TODO: still fails on some records... RecordsStresser.handleWorkbook(wb);
}
Also used : HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 62 with HSSFWorkbook

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

the class TestDrawingAggregate method testSerializeDrawingBigger8k_noAggregation.

@Test
public void testSerializeDrawingBigger8k_noAggregation() throws IOException {
    HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("DrawingContinue.xls");
    InternalSheet isheet = HSSFTestHelper.getSheetForTest(wb1.getSheetAt(0));
    List<RecordBase> records = isheet.getRecords();
    HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    InternalSheet isheet2 = HSSFTestHelper.getSheetForTest(wb2.getSheetAt(0));
    List<RecordBase> records2 = isheet2.getRecords();
    assertEquals(records.size(), records2.size());
    for (int i = 0; i < records.size(); i++) {
        RecordBase r1 = records.get(i);
        RecordBase r2 = records2.get(i);
        assertTrue(r1.getClass() == r2.getClass());
        assertEquals(r1.getRecordSize(), r2.getRecordSize());
        if (r1 instanceof Record) {
            assertEquals(((Record) r1).getSid(), ((Record) r2).getSid());
            assertArrayEquals(((Record) r1).serialize(), ((Record) r2).serialize());
        }
    }
    wb2.close();
}
Also used : RecordBase(org.apache.poi.hssf.record.RecordBase) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) TextObjectRecord(org.apache.poi.hssf.record.TextObjectRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) ContinueRecord(org.apache.poi.hssf.record.ContinueRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) Record(org.apache.poi.hssf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) ObjRecord(org.apache.poi.hssf.record.ObjRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 63 with HSSFWorkbook

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

the class TestDrawingAggregate method testFailing.

/**
     * TODO: figure out why it fails with "RecordFormatException: 0 bytes written but getRecordSize() reports 80"
     */
@Test
public void testFailing() throws IOException {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("15573.xls");
    HSSFSheet sh = wb.getSheetAt(0);
    sh.getDrawingPatriarch();
    HSSFTestDataSamples.writeOutAndReadBack(wb).close();
    wb.close();
}
Also used : HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 64 with HSSFWorkbook

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

the class TestDrawingShapes method testShapeContainerImplementsIterable.

@SuppressWarnings("unused")
@Test
public void testShapeContainerImplementsIterable() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    patriarch.createSimpleShape(new HSSFClientAnchor());
    patriarch.createSimpleShape(new HSSFClientAnchor());
    int i = 2;
    for (HSSFShape shape : patriarch) {
        i--;
    }
    assertEquals(i, 0);
    wb.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFShape(org.apache.poi.hssf.usermodel.HSSFShape) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 65 with HSSFWorkbook

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

the class TestHPSFPropertiesExtractor method testConstructors.

public void testConstructors() throws IOException {
    POIFSFileSystem fs;
    HSSFWorkbook wb;
    try {
        fs = new POIFSFileSystem(_samples.openResourceAsStream("TestUnicode.xls"));
        wb = new HSSFWorkbook(fs);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    ExcelExtractor excelExt = new ExcelExtractor(wb);
    final String fsText;
    HPSFPropertiesExtractor fsExt = new HPSFPropertiesExtractor(fs);
    // Don't close re-used test resources!
    fsExt.setFilesystem(null);
    try {
        fsText = fsExt.getText();
    } finally {
        fsExt.close();
    }
    final String hwText;
    HPSFPropertiesExtractor hwExt = new HPSFPropertiesExtractor(wb);
    // Don't close re-used test resources!
    hwExt.setFilesystem(null);
    try {
        hwText = hwExt.getText();
    } finally {
        hwExt.close();
    }
    final String eeText;
    HPSFPropertiesExtractor eeExt = new HPSFPropertiesExtractor(excelExt);
    // Don't close re-used test resources!
    eeExt.setFilesystem(null);
    try {
        eeText = eeExt.getText();
    } finally {
        eeExt.close();
        wb.close();
    }
    assertEquals(fsText, hwText);
    assertEquals(fsText, eeText);
    assertContains(fsText, "AUTHOR = marshall");
    assertContains(fsText, "TITLE = Titel: Äh");
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) ExcelExtractor(org.apache.poi.hssf.extractor.ExcelExtractor) IOException(java.io.IOException) 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