我正在尝试在浏览器中而不是在MS Excel中打开xls表。我已经尝试过,Desktop.getDesktop().browse(fileName.toURI());
但是没有用。这是execute方法的完整代码:
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());
}
无论如何,这只能通过Microsoft Office Excel应用程序打开excel,但是只能通过Netbeans运行该项目。如果我尝试从没有Netbeans的Tomcat中打开它,那么它将无法正常工作。
attachment
inline
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句