@Test @Ignore public void testStreamToFile() throws Exception { XLSXStreamer streamer = new XLSXStreamer(); HSSFWorkbook wb = new HSSFWorkbook(); FileOutputStream out = new FileOutputStream("workbook.xlsx"); String[] headers = {"hello", "world"}; Object[][] data = { {"100.0", "101.0"}, {"200.0", "201.0"}, }; Map<String, Object> additionalFields = new HashMap<>(); additionalFields.put("add1", "val1"); additionalFields.put("add2", "val2"); streamer.writeToStream(headers, data, additionalFields, out); }
@Override public void writeToStream(String[] headers, Object[][] data, Map<String, Object> additionalFields, OutputStream out) throws IOException { Workbook wb = new SXSSFWorkbook(); Sheet sh = wb.createSheet(); Object[] rowArray; int cellNum, rowNum = 0; Row row = sh.createRow(rowNum); Cell cell; Object value; for (cellNum = 0; cellNum < headers.length; cellNum++) { cell = row.createCell(cellNum); fillCell(cell, headers[cellNum]); } for (rowNum = 1; rowNum < data.length+1; rowNum++) { rowArray = data[rowNum-1]; row = sh.createRow(rowNum); for (cellNum = 0; cellNum < rowArray.length; cellNum++) { value = rowArray[cellNum]; cell = row.createCell(cellNum); fillCell(cell, value); } } if (!additionalFields.isEmpty()) { row = sh.createRow(rowNum); rowNum++; } for (Map.Entry<String, Object> entry : additionalFields.entrySet()) { row = sh.createRow(rowNum); cell = row.createCell(0); fillCell(cell, entry.getKey()); cell = row.createCell(1); fillCell(cell, entry.getValue()); rowNum++; } wb.write(out); out.flush(); out.close(); }
XLSXStreamer implements TabularFileStreamer { @Override public void writeToStream(String[] headers, Object[][] data, Map<String, Object> additionalFields, OutputStream out) throws IOException { Workbook wb = new SXSSFWorkbook(); Sheet sh = wb.createSheet(); Object[] rowArray; int cellNum, rowNum = 0; Row row = sh.createRow(rowNum); Cell cell; Object value; for (cellNum = 0; cellNum < headers.length; cellNum++) { cell = row.createCell(cellNum); fillCell(cell, headers[cellNum]); } for (rowNum = 1; rowNum < data.length+1; rowNum++) { rowArray = data[rowNum-1]; row = sh.createRow(rowNum); for (cellNum = 0; cellNum < rowArray.length; cellNum++) { value = rowArray[cellNum]; cell = row.createCell(cellNum); fillCell(cell, value); } } if (!additionalFields.isEmpty()) { row = sh.createRow(rowNum); rowNum++; } for (Map.Entry<String, Object> entry : additionalFields.entrySet()) { row = sh.createRow(rowNum); cell = row.createCell(0); fillCell(cell, entry.getKey()); cell = row.createCell(1); fillCell(cell, entry.getValue()); rowNum++; } wb.write(out); out.flush(); out.close(); } }
XLSXStreamer implements TabularFileStreamer { @Override public void writeToStream(String[] headers, Object[][] data, Map<String, Object> additionalFields, OutputStream out) throws IOException { Workbook wb = new SXSSFWorkbook(); Sheet sh = wb.createSheet(); Object[] rowArray; int cellNum, rowNum = 0; Row row = sh.createRow(rowNum); Cell cell; Object value; for (cellNum = 0; cellNum < headers.length; cellNum++) { cell = row.createCell(cellNum); fillCell(cell, headers[cellNum]); } for (rowNum = 1; rowNum < data.length+1; rowNum++) { rowArray = data[rowNum-1]; row = sh.createRow(rowNum); for (cellNum = 0; cellNum < rowArray.length; cellNum++) { value = rowArray[cellNum]; cell = row.createCell(cellNum); fillCell(cell, value); } } if (!additionalFields.isEmpty()) { row = sh.createRow(rowNum); rowNum++; } for (Map.Entry<String, Object> entry : additionalFields.entrySet()) { row = sh.createRow(rowNum); cell = row.createCell(0); fillCell(cell, entry.getKey()); cell = row.createCell(1); fillCell(cell, entry.getValue()); rowNum++; } wb.write(out); out.flush(); out.close(); }  }
XLSXStreamer implements TabularFileStreamer { @Override public void writeToStream(String[] headers, Object[][] data, Map<String, Object> additionalFields, OutputStream out) throws IOException { Workbook wb = new SXSSFWorkbook(); Sheet sh = wb.createSheet(); Object[] rowArray; int cellNum, rowNum = 0; Row row = sh.createRow(rowNum); Cell cell; Object value; for (cellNum = 0; cellNum < headers.length; cellNum++) { cell = row.createCell(cellNum); fillCell(cell, headers[cellNum]); } for (rowNum = 1; rowNum < data.length+1; rowNum++) { rowArray = data[rowNum-1]; row = sh.createRow(rowNum); for (cellNum = 0; cellNum < rowArray.length; cellNum++) { value = rowArray[cellNum]; cell = row.createCell(cellNum); fillCell(cell, value); } } if (!additionalFields.isEmpty()) { row = sh.createRow(rowNum); rowNum++; } for (Map.Entry<String, Object> entry : additionalFields.entrySet()) { row = sh.createRow(rowNum); cell = row.createCell(0); fillCell(cell, entry.getKey()); cell = row.createCell(1); fillCell(cell, entry.getValue()); rowNum++; } wb.write(out); out.flush(); out.close(); }  @Override void writeToStream(String[] headers, Object[][] data, Map<String, Object> additionalFields, OutputStream out); }
XLSXStreamer implements TabularFileStreamer { @Override public void writeToStream(String[] headers, Object[][] data, Map<String, Object> additionalFields, OutputStream out) throws IOException { Workbook wb = new SXSSFWorkbook(); Sheet sh = wb.createSheet(); Object[] rowArray; int cellNum, rowNum = 0; Row row = sh.createRow(rowNum); Cell cell; Object value; for (cellNum = 0; cellNum < headers.length; cellNum++) { cell = row.createCell(cellNum); fillCell(cell, headers[cellNum]); } for (rowNum = 1; rowNum < data.length+1; rowNum++) { rowArray = data[rowNum-1]; row = sh.createRow(rowNum); for (cellNum = 0; cellNum < rowArray.length; cellNum++) { value = rowArray[cellNum]; cell = row.createCell(cellNum); fillCell(cell, value); } } if (!additionalFields.isEmpty()) { row = sh.createRow(rowNum); rowNum++; } for (Map.Entry<String, Object> entry : additionalFields.entrySet()) { row = sh.createRow(rowNum); cell = row.createCell(0); fillCell(cell, entry.getKey()); cell = row.createCell(1); fillCell(cell, entry.getValue()); rowNum++; } wb.write(out); out.flush(); out.close(); }  @Override void writeToStream(String[] headers, Object[][] data, Map<String, Object> additionalFields, OutputStream out);  }