Search in sources :

Example 1 with SXSSFWorkbook

use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project tdi-studio-se by Talend.

the class ExcelTool method prepareStream.

public void prepareStream() throws Exception {
    wb = new SXSSFWorkbook(rowAccessWindowSize);
    sheet = wb.createSheet(sheetName);
    if (isAbsY) {
        startX = absX;
        curY = absY;
    }
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook)

Example 2 with SXSSFWorkbook

use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project tdi-studio-se by Talend.

the class ExcelTool method prepareXlsxFile.

public void prepareXlsxFile(String fileName) throws Exception {
    File xlsxFile = new File(fileName);
    if (xlsxFile.exists()) {
        if (isAbsY && keepCellFormat) {
            initPreXlsx(fileName);
        }
        if (appendWorkbook) {
            InputStream inp = new FileInputStream(fileName);
            wb = WorkbookFactory.create(inp);
            sheet = wb.getSheet(sheetName);
            if (sheet != null) {
                if (appendSheet) {
                    if (sheet.getLastRowNum() != 0 || sheet.getRow(0) != null) {
                        curY = sheet.getLastRowNum() + 1;
                    }
                } else {
                    wb.removeSheetAt(wb.getSheetIndex(sheetName));
                    sheet = wb.createSheet(sheetName);
                }
            } else {
                sheet = wb.createSheet(sheetName);
            }
        } else {
            xlsxFile.delete();
            wb = new SXSSFWorkbook(rowAccessWindowSize);
            sheet = wb.createSheet(sheetName);
        }
    } else {
        wb = new SXSSFWorkbook(rowAccessWindowSize);
        sheet = wb.createSheet(sheetName);
    }
    if (isAbsY) {
        startX = absX;
        curY = absY;
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with SXSSFWorkbook

use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.

the class Outlining method collapseRow.

private void collapseRow() throws IOException {
    SXSSFWorkbook wb2 = new SXSSFWorkbook(100);
    SXSSFSheet sheet2 = wb2.createSheet("new sheet");
    int rowCount = 20;
    for (int i = 0; i < rowCount; i++) {
        sheet2.createRow(i);
    }
    sheet2.groupRow(4, 9);
    sheet2.groupRow(11, 19);
    sheet2.setRowGroupCollapsed(4, true);
    FileOutputStream fileOut = new FileOutputStream("outlining_collapsed.xlsx");
    try {
        wb2.write(fileOut);
    } finally {
        fileOut.close();
        wb2.dispose();
        wb2.close();
    }
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) FileOutputStream(java.io.FileOutputStream) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet)

Example 4 with SXSSFWorkbook

use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.

the class TestSXSSFBugs method bug49253.

/**
     * Setting repeating rows and columns shouldn't break
     *  any print settings that were there before
     */
@Test
public void bug49253() throws Exception {
    Workbook wb1 = new SXSSFWorkbook();
    Workbook wb2 = new SXSSFWorkbook();
    CellRangeAddress cra = CellRangeAddress.valueOf("C2:D3");
    // No print settings before repeating
    Sheet s1 = wb1.createSheet();
    s1.setRepeatingColumns(cra);
    s1.setRepeatingRows(cra);
    PrintSetup ps1 = s1.getPrintSetup();
    assertEquals(false, ps1.getValidSettings());
    assertEquals(false, ps1.getLandscape());
    // Had valid print settings before repeating
    Sheet s2 = wb2.createSheet();
    PrintSetup ps2 = s2.getPrintSetup();
    ps2.setLandscape(false);
    assertEquals(true, ps2.getValidSettings());
    assertEquals(false, ps2.getLandscape());
    s2.setRepeatingColumns(cra);
    s2.setRepeatingRows(cra);
    ps2 = s2.getPrintSetup();
    assertEquals(true, ps2.getValidSettings());
    assertEquals(false, ps2.getLandscape());
    wb1.close();
    wb2.close();
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) PrintSetup(org.apache.poi.ss.usermodel.PrintSetup) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 5 with SXSSFWorkbook

use of org.apache.poi.xssf.streaming.SXSSFWorkbook in project poi by apache.

the class TestUnfixedBugs method testBug54084Unicode.

@Test
public void testBug54084Unicode() throws IOException {
    // sample XLSX with the same text-contents as the text-file above
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("54084 - Greek - beyond BMP.xlsx");
    verifyBug54084Unicode(wb);
    //        OutputStream baos = new FileOutputStream("/tmp/test.xlsx");
    //        try {
    //            wb.write(baos);
    //        } finally {
    //            baos.close();
    //        }
    // now write the file and read it back in
    XSSFWorkbook wbWritten = XSSFTestDataSamples.writeOutAndReadBack(wb);
    verifyBug54084Unicode(wbWritten);
    // finally also write it out via the streaming interface and verify that we still can read it back in
    SXSSFWorkbook swb = new SXSSFWorkbook(wb);
    Workbook wbStreamingWritten = SXSSFITestDataProvider.instance.writeOutAndReadBack(swb);
    verifyBug54084Unicode(wbStreamingWritten);
    wbWritten.close();
    swb.close();
    wbStreamingWritten.close();
    wb.close();
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Aggregations

SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)19 Test (org.junit.Test)7 Workbook (org.apache.poi.ss.usermodel.Workbook)6 Sheet (org.apache.poi.ss.usermodel.Sheet)5 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 FileInputStream (java.io.FileInputStream)3 Cell (org.apache.poi.ss.usermodel.Cell)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)2 BaseTestXSheet (org.apache.poi.ss.usermodel.BaseTestXSheet)2 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)2 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)2 RichTextString (org.apache.poi.ss.usermodel.RichTextString)2 Row (org.apache.poi.ss.usermodel.Row)2 TempFile (org.apache.poi.util.TempFile)2