MecGrid是一个开源的报表组件,似乎是小日本写的,功能挺强大的就是不公布源代码,官方提供的导出Excel功能只是Air专用的(因为web的flex程序没有File类),看了下代码后觉得web也是可以实现的。
具体的思路就是把生成的二进制数据传到服务器端,由服务器生成文件。
具体的代码如下
前台:
private function makeExcelFile(event:Event):void
{
var exp:MecExporter = new MecExporter();
exp.charset = "UTF-8";
exp.AddDataGrid(mgrid, "");
var ebt:ByteArray = exp.Export2BiffExcel();
var param:Object=new Object();
param.data=ebt;
param.path="tools";
param.fileName="mecgrid";
JdbcService.getInstance(true).callfunc("UserService","exportExcel",param,null,null);
// var f:File= event.target as File;
// var fs:FileStream = new FileStream();
// fs.open(f, FileMode.WRITE);
// fs.writeBytes(ebt);
// fs.close();
}
后台:
/**
* Creates the excel.MECGrid导出Excel
*
* @param param the param
*
* @return the string 导出成功返回文件的路径否则返回null
*/
public String createExcel(ASObject param){
String path=(String) param.get("path");
String fileName=(String)param.get("fileName");
String uri=FlexContext.getServletContext().getRealPath("");
//1 导出文件保存的路径 相对路径
String inPath=uri+"/upload/"+path+"/"+fileName;
//2 MecGrid生成的数据信息
byte[] b=(byte[]) param.get("data");
BufferedOutputStream stream = null;
File file = null;
try {
logger.debug("导出Excel路径"+inPath);
file = new File(inPath);
FileOutputStream fstream = new FileOutputStream(file);
stream = new BufferedOutputStream(fstream);
stream.write(b);
} catch (Exception e) {
logger.debug(e.getMessage(),e);
logger.info("导出excel时发生异常");
return null;
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e1) {
logger.debug(e1.getMessage(),e1);
}
}
}
return inPath;
}
备注:刚开始在网上查了些资料,网上有人说只能用air生成excel文件,看了官方的例子后,觉得可以实现web导出excel的。
分享到:
相关推荐
flex MecExporter(2).swc MecExporter(2).swc
在FLEX中使用MecGrid的Excel导出功能是一个常见的需求,特别是在开发数据密集型应用程序时,用户往往需要将展示的数据导出为Excel格式以便于分析或存储。本篇文章将详细探讨如何在Flex项目中集成并利用MecGrid库来...
AdvancedDataGrid导出复杂表头excel
MecGrid是一款功能强大且漂亮的组件,几天用下来非常满意,但是该组件导出为Excel只支持Air桌面程序,由于业务需要画了点时间做了一下,该实例可以在Flex Web应用中导出Excel表,导出效果和Air下导出的效果一样,...
在实际开发过程中,开发者还可以根据需求利用MecGrid提供的API进行扩展,比如实现导出表格到Excel的功能。通过使用MecExporter类,我们可以将MecGrid中的数据转换为Excel格式,方便用户进行离线分析或与其他应用程序...
Mecgrid Mecgrid是一个开放API但不开放源代码的免费报表组件 具体特性如下所示: 可以得到横纵列的索引 支持鼠标滚动 ...导出excel文件格式(AIR专有) 支持过滤功能。 单元格拖拽功能。 多列排序功能。
具体特性如下所示: 可以得到横纵列的索引 支持鼠标滚动 支持分成结构(即树形结构) 单元格自定义样式 同样具体dataProvider功能 导出excel文件格式(AIR专有) 支持过滤功能。 单元格拖拽功能。 多列排序功能。