Search in sources :

Example 1 with SXSSFSheet

use of org.apache.poi.xssf.streaming.SXSSFSheet 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 2 with SXSSFSheet

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

the class SavePasswordProtectedXlsx method main.

public static void main(String[] args) throws Exception {
    if (args.length != 2) {
        throw new IllegalArgumentException("Expected 2 params: filename and password");
    }
    TempFileUtils.checkTempFiles();
    String filename = args[0];
    String password = args[1];
    SXSSFWorkbookWithCustomZipEntrySource wb = new SXSSFWorkbookWithCustomZipEntrySource();
    try {
        for (int i = 0; i < 10; i++) {
            SXSSFSheet sheet = wb.createSheet("Sheet" + i);
            for (int r = 0; r < 1000; r++) {
                SXSSFRow row = sheet.createRow(r);
                for (int c = 0; c < 100; c++) {
                    SXSSFCell cell = row.createCell(c);
                    cell.setCellValue("abcd");
                }
            }
        }
        EncryptedTempData tempData = new EncryptedTempData();
        try {
            wb.write(tempData.getOutputStream());
            save(tempData.getInputStream(), filename, password);
            System.out.println("Saved " + filename);
        } finally {
            tempData.dispose();
        }
    } finally {
        wb.close();
        wb.dispose();
    }
    TempFileUtils.checkTempFiles();
}
Also used : EncryptedTempData(org.apache.poi.poifs.crypt.temp.EncryptedTempData) SXSSFWorkbookWithCustomZipEntrySource(org.apache.poi.poifs.crypt.temp.SXSSFWorkbookWithCustomZipEntrySource) SXSSFRow(org.apache.poi.xssf.streaming.SXSSFRow) SXSSFCell(org.apache.poi.xssf.streaming.SXSSFCell) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet)

Example 3 with SXSSFSheet

use of org.apache.poi.xssf.streaming.SXSSFSheet in project tika by apache.

the class Report method dumpReportToWorkbook.

private void dumpReportToWorkbook(Statement st, SXSSFWorkbook wb) throws IOException, SQLException {
    ResultSet rs = st.executeQuery(sql);
    SXSSFSheet sheet = wb.createSheet("tika-eval Report");
    sheet.trackColumnForAutoSizing(0);
    int rowCount = 0;
    ResultSetMetaData meta = rs.getMetaData();
    Set<String> colNames = new HashSet<>();
    Row xssfRow = sheet.createRow(rowCount++);
    //write headers and cache them to check against styles
    for (int i = 1; i <= meta.getColumnCount(); i++) {
        Cell cell = xssfRow.createCell(i - 1);
        cell.setCellValue(meta.getColumnLabel(i));
        colNames.add(meta.getColumnLabel(i));
    }
    ResultSetMetaData resultSetMetaData = rs.getMetaData();
    while (rs.next()) {
        xssfRow = sheet.createRow(rowCount++);
        for (int i = 1; i <= meta.getColumnCount(); i++) {
            Cell cell = xssfRow.createCell(i - 1);
            XSLXCellFormatter formatter = cellFormatters.get(meta.getColumnLabel(i));
            if (formatter == null) {
                formatter = getDefaultFormatter(resultSetMetaData.getColumnType(i));
            }
            if (formatter != null) {
                formatter.applyStyleAndValue(i, rs, cell);
            } else {
                writeCell(meta, i, rs, cell);
            }
        }
    }
    sheet.autoSizeColumn(0);
    if (!includeSql) {
        return;
    }
    SXSSFSheet sqlSheet = wb.createSheet("tika-eval SQL");
    sqlSheet.setColumnWidth(0, 100 * 250);
    Row sqlRow = sqlSheet.createRow(0);
    short height = 5000;
    sqlRow.setHeight(height);
    Cell cell = sqlRow.createCell(0);
    cell.setCellStyle(sqlCellStyle);
    //.replaceAll("[\r\n]+", "\r\n"));
    cell.setCellValue(sql.trim());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ResultSet(java.sql.ResultSet) Row(org.apache.poi.ss.usermodel.Row) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet) Cell(org.apache.poi.ss.usermodel.Cell) HashSet(java.util.HashSet)

Aggregations

SXSSFSheet (org.apache.poi.xssf.streaming.SXSSFSheet)3 FileOutputStream (java.io.FileOutputStream)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 HashSet (java.util.HashSet)1 EncryptedTempData (org.apache.poi.poifs.crypt.temp.EncryptedTempData)1 SXSSFWorkbookWithCustomZipEntrySource (org.apache.poi.poifs.crypt.temp.SXSSFWorkbookWithCustomZipEntrySource)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 SXSSFCell (org.apache.poi.xssf.streaming.SXSSFCell)1 SXSSFRow (org.apache.poi.xssf.streaming.SXSSFRow)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1