Java Excel Api 如何实现如下功能?

04-08-24 zrweng
1.如何用JavaExcelApi在web中打开指定的excel文件?

2.如何对已打开的excel进行编辑后可以直接保存?

可能我描述的不够清楚,希望大家理解, 找了些资料,以下是通过Outputstream打开新创建的excel文件,例子:

public static void writeExcel(OutputStream os) throws Exception {

jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os);

jxl.write.WritableSheet ws = wwb.createSheet("TestSheet1", 0);

jxl.write.Label labelC = new jxl.write.Label(0, 0, "我爱中国");

ws.addCell(labelC);

jxl.write.WritableFont wfc = new jxl.write.WritableFont(WritableFont.ARIAL,

20, WritableFont.BOLD, false,

UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.GREEN);

jxl.write.WritableCellFormat wcfFC = new jxl.write.WritableCellFormat(wfc);

wcfFC.setBackground(jxl.format.Colour.RED);

labelC = new jxl.write.Label(6, 0, "中国爱我",wcfFC);

ws.addCell(labelC);

//写入Exel工作表

wwb.write();

//关闭Excel工作薄对象

wwb.close();

}

test.jsp:

<%

response.reset();

response.setContentType("application/vnd.ms-excel");

Test.writeExcel(response.getOutputStream());

%>

测试以上例子,可以打开文件,但是在Excel中直接编辑后,无法保存!

如果要保存需要在javabean中去重新set每个Cell的值,这又如何实现保存呢(或者也可以直接在excel中编辑后,重新上传该文件,覆盖)?

谁实现过类似功能,或其他实现方案,还望给个事例,谢谢!

zrweng
2004-08-24 09:27
上面漏掉了,补充:

test.jsp:

<%

response.reset();

response.setContentType("application/vnd.ms-excel");

Test.writeExcel(response.getOutputStream());

%>

zrweng
2004-08-24 09:28
:(

test.jsp:

<%
response.reset();
response.setContentType("application/vnd.ms-excel");
Test.writeExcel(response.getOutputStream());
%>
<p>

猜你喜欢