将文档导出为单词 [英] Export Document to word
本文介绍了将文档导出为单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi,
我想导出包含文本,图像,表格,链接的文档(.aspx)使用css和活动链接转换为PDF。我无法在IE中获取图像。我在chrome中使用了filesaver.js和wordexport.js它工作正常。
I want to export the document(.aspx) which contains text, images, tables, links in to PDF with css and active links. I am unable to get the images in IE. I used filesaver.js and wordexport.js in chrome it is working fine.
谢谢。
推荐答案
您好Jyoti,
Hi Jyoti,
这是一个JavaScript,它将aspx页面内容导出到带有图像的Word文档中:
Here is a JavaScript which will export aspx page content into Word Document with image:
<script type="text/javascript">
function Export2Doc(element) {
var preHtml = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'><head><meta charset='utf-8'><title>Export HTML To Doc</title></head><body>";
var postHtml = "</body></html>";
var html = preHtml + document.getElementById(element).innerHTML + postHtml;
var blob = new Blob(['\ufeff', html], {
type: 'application/msword'
});
// Specify link url
var url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(html);
// Specify file name
filename = 'document.doc';
// Create download link element
var downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
if (navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(blob, filename);
} else {
// Create a link to the file
downloadLink.href = url;
// Setting the file name
downloadLink.download = filename;
//triggering the function
downloadLink.click();
}
document.body.removeChild(downloadLink);
}
</script>
<button onclick="Export2Doc('exportContent');">Export as .doc</button>
<div id="exportContent">
<img src="http://sp/SiteAssets/Bac.png" alt="test">
Test Text
</div>
在IE 11中测试:
参考:
谢谢
最好的问候
这篇关于将文档导出为单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文