Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

POI HSSFWorkbook into Excel without file

843810Dec 19 2003 — edited Dec 19 2003
Hi,
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();
...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 16 2004
Added on Dec 19 2003
3 comments
649 views