flex中导出excel

没啥难度,不过留着存档

server端struts2,利用poi生成excel:


public void excel() {
System.out.println("come on!");
HttpServletResponse response = ServletActionContext.getResponse();
try {
//设置返回类型为excel
response.setContentType("application/vnd.ms-excel; charset=UTF-8");

//设置返回文件名为aaa.xls
response.setHeader("Content-Disposition", "filename=aaa.xls");
response.setHeader("Cache-Control", "no-cache");

//利用poi生成excel
int index = 1;
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
HSSFRow row = sheet.createRow(index++);
HSSFCell cell = row.createCell(0, HSSFCell.CELL_TYPE_STRING);
HSSFRichTextString str = new HSSFRichTextString("1");
cell.setCellValue(str);
cell = row.createCell(1, HSSFCell.CELL_TYPE_STRING);
str = new HSSFRichTextString("2");
cell.setCellValue(str);
cell = row.createCell(2, HSSFCell.CELL_TYPE_STRING);
str = new HSSFRichTextString("3");
cell.setCellValue(str);
cell = row.createCell(3, HSSFCell.CELL_TYPE_STRING);
str = new HSSFRichTextString("4");
cell.setCellValue(str);
//将生成的excel通过response返回
workbook.write(response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
}


client端flex,demo:


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.navigateToURL;
public function export(url:String):void{
var u:URLRequest = new URLRequest(url);
url.method = URLRequestMethod.POST;
navigateToURL(url,"_blank");
}
]]>
</mx:Script>
<mx:Button label="导出excel" click="export('http://localhost:8080/webtest/abc_excel.action')"/>
</mx:Application>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值