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();
}
}
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();
}
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());
}
Aggregations