首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CSS >

Extjs htmleditor中内容导出成word (2)

2012-09-04 
Extjs htmleditor中内容导出成word (二)上一篇我们讲了怎样把Extjs htmleditor的内容保存成Word,这一篇,我

Extjs htmleditor中内容导出成word (二)

上一篇我们讲了怎样把Extjs htmleditor的内容保存成Word,这一篇,我们主要讲怎样在客服端(浏览器端)保存htmleditor里的内容成word。


首先介绍两个Javascript框架:

1、 downloadify

这是一个非常小的Javascript+Flash库,它允许用户在浏览器端保存内容到用户的PC,不需要和服务器交互。

项目Demo:http://pixelgraphics.us/downloadify/test.html

项目主页: https://github.com/dcneiner/Downloadify


2、opensave

opensave 是一个小巧的Javascript和ActionScript(SWF)的文件打开和文件保存的库,它可以open用户本地文件在浏览器里显示,同时也可以save浏览器里的页面到用户的电脑里。

项目主页: http://www.gieson.com/Library/projects/utilities/opensave/


downloadify 仅提供了下载功能,opensave提供了open 本地文件功能,同时也能定制button的text,功能更加强大。


由于downloadify小巧,我们的另外一个扩展库(Extjs Gridpanel 导出成excel)也使用到了downloadify,所以决定使用downloadify。

页面里没用使用Extjs的话,可以参考他们的demo很容易实现导出,下面我们主要讲解在Extjs里加入downloadify导出word。


废话少说,直接贴代码:

jsp 文件:

Downloadify.create(button.getId(), {filename: function(){return "审计工作方案.doc";},data: function(){ var headerStart = "<html xmlns:v='urn:schemas-microsoft-com:vml' " +"xmlns:o='urn:schemas-microsoft-com:office:office'" +"xmlns:w='urn:schemas-microsoft-com:office:word'" +"xmlns:m='http://schemas.microsoft.com/office/2004/12/omml'" +"xmlns='http://www.w3.org/TR/REC-html40'> ";var headerEnd = "</html> ";return headerStart+Ext.getCmp("content").getValue()+headerEnd;},onComplete: function(){ alert('文件导出成功!'); },onCancel: function(){ alert('您取消了文件导出!'); },onError: function(){ alert('文件导出失败!'); },swf: webpath+'/extjs/exporter/downloadify.swf',downloadImage: webpath+'/extjs/exporter/images/export-word.png',width: 58,height: 28,transparent: true,append: false});

用到的Extjs exporter 里可以再这里下载(额外提供了几个导出图片)或去她的主页下载。

热点排行