Search in sources :

Example 1 with SXSSFRow

use of org.apache.poi.xssf.streaming.SXSSFRow 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)

Aggregations

EncryptedTempData (org.apache.poi.poifs.crypt.temp.EncryptedTempData)1 SXSSFWorkbookWithCustomZipEntrySource (org.apache.poi.poifs.crypt.temp.SXSSFWorkbookWithCustomZipEntrySource)1 SXSSFCell (org.apache.poi.xssf.streaming.SXSSFCell)1 SXSSFRow (org.apache.poi.xssf.streaming.SXSSFRow)1 SXSSFSheet (org.apache.poi.xssf.streaming.SXSSFSheet)1