`
unbounder
  • 浏览: 171754 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

flex中导出excel

    博客分类:
  • flex
阅读更多
没啥难度,不过留着存档

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
6
分享到:
评论
1 楼 linfeng0169 2013-05-13  
这个方法 现在是不是不能用了啊  因为 我不会struts 所以没写明白那个action 但是flex这边如果这么写的话 会有一个错误
引用
找到多个构造函数定义。可能无法在 <Script/> 代码中
定义构造函数。

相关推荐

Global site tag (gtag.js) - Google Analytics