I'm trying to open an xls sheet in the browser, not in MS Excel. I've tried with Desktop.getDesktop().browse(fileName.toURI());
but is not working. This is the complete code of the execute method:
public String execute() throws Exception
{
String rutaArchivo = System.getProperty("catalina.base")+"/ejemploExcelJava.xls";
File archivoXLS = new File(rutaArchivo);
if(archivoXLS.exists()) {
archivoXLS.delete();
}
archivoXLS.createNewFile();
Workbook libro = new HSSFWorkbook();
FileOutputStream archivo = new FileOutputStream(archivoXLS);
Sheet hoja = libro.createSheet("Mi hoja de trabajo 1");
Date fechaActual = new Date();
for (int f = 0; f < 10; f++) {
Row fila = hoja.createRow(f);
for (int c = 0; c < 5; c++) {
Cell celda = fila.createCell(c);
if (f == 0) {
celda.setCellValue("Encabezado #" + c);
} else {
celda.setCellValue(fechaActual.getHours() + ":" + fechaActual.getMinutes());
}
}
}
libro.write(archivo);
archivo.close();
Desktop.getDesktop().browse(archivoXLS.toURI());
}
Anyway, this works opening excel from Microsoft Office Excel application, but only by running the project from Netbeans. If I try to open it from Tomcat without Netbeans, it doesn't work.
attachment
toinline
;