POI HSSFWorkbook into Excel without file
843810Dec 19 2003 — edited Dec 19 2003Hi,
I try to use POI to generate an Excel sheet that i can display immediatly in Excel. If i have to create an Excel file with POI, there is no problem. What i want to do is to write in the OutputStream of Excel. Is is possible.
Here is what i have tried. It is not running.
...
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = { "c:\\Program Files\\Microsoft Office\\Office\\Excel.exe" };
Process pExcel = rt.exec(callAndArgs);
OutputStream isExcel = pExcel.getInputStream();
OutputStream osExcel = pExcel.getOutputStream();
HSSFWorkbook wb = new HSSFWorkbook(isExcel);
wb.removeSheetAt(1);//Sheet2
wb.removeSheetAt(0);//Sheet1
HSSFSheet sheet = wb.createSheet("DATA");
HSSFRow row = null;
HSSFCell cell = null;
HSSFCellStyle cellDateStyle = wb.createCellStyle();
cellDateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
for(int i = 0; i < 10; i++) {
row = sheet.createRow(i);
row.createCell((short)0).setCellValue("ROW");
row.createCell((short)1).setCellValue(i * 1000);
}
wb.write(osExcel);// Write to the Stream
osExcel.flush();
pExcel.waitFor();
osExcel.close();
isExcel.close();
...