JS-WORD完善结合之模板化
2010-12-17 09:55
281 查看
在实际开发中,会遇到在WORD提供的模板中,插入特定的信息。如下模板:
JS操作WORD测试
生成结果:
JS操作WORD测试
代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>JS test</title>
</head>
<body>
<button id='testBtn' onclick='onTest()'>TEST</button>
</body>
<script>
function onTest()
{
var po = {};
po.name = '涛哥';
po.sex = '男';
po.mz = '汉';
po.address = '地球3号';
po.template = 'http://localhost:9090/log/jsword/jstest.docx';
po.photo = 'http://www.baidu.com/img/logo-yy.gif';
exportWord(po);
}
function exportWord(po)
{
var wApp = new ActiveXObject("Word.Application");
wApp.Application.Visible = true;
var doc = wApp.Documents.Open(po.template);
var fnd = doc.Content.Find;
var bOK = fnd.Execute('${name}', true, true, false, false, false, true, 0 , false, po.name, 2);
bOK = fnd.Execute('${sex}', true, true, false, false, false, true, 0 , false, po.sex, 2);
bOK = fnd.Execute('${mz}', true, true, false, false, false, true, 0 , false, po.mz, 2);
bOK = fnd.Execute('${address}', true, true, false, false, false, true, 0 , false, po.address, 2);
var cell = doc.Tables(1).Cell(1,7);
cell.Range.InlineShapes.AddPicture(po.photo);
//Execute('${name}', true, true, false, false, false, true, WdFindWrap , false, name, wdReplaceAll, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl, MatchPrefix, MatchSuffix, MatchPhrase, IgnoreSpace, IgnorePunct);
}
</script>
</html>
JS操作WORD测试
姓名 | ${name} | 性别 | ${sex} | 民族 | ${mz} | ${photo} |
住址 | ${address} | |||||
${name} | ${name} | ${name} | ||||
${name} | ${name} | ${name} | ||||
${name} | ${name} | ${name} |
JS操作WORD测试
姓名 | 涛哥 | 性别 | 男 | 民族 | 汉 | |
住址 | 地球3号 | |||||
涛哥 | 涛哥 | 涛哥 | ||||
涛哥 | 涛哥 | 涛哥 | ||||
涛哥 | 涛哥 | 涛哥 |
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>JS test</title>
</head>
<body>
<button id='testBtn' onclick='onTest()'>TEST</button>
</body>
<script>
function onTest()
{
var po = {};
po.name = '涛哥';
po.sex = '男';
po.mz = '汉';
po.address = '地球3号';
po.template = 'http://localhost:9090/log/jsword/jstest.docx';
po.photo = 'http://www.baidu.com/img/logo-yy.gif';
exportWord(po);
}
function exportWord(po)
{
var wApp = new ActiveXObject("Word.Application");
wApp.Application.Visible = true;
var doc = wApp.Documents.Open(po.template);
var fnd = doc.Content.Find;
var bOK = fnd.Execute('${name}', true, true, false, false, false, true, 0 , false, po.name, 2);
bOK = fnd.Execute('${sex}', true, true, false, false, false, true, 0 , false, po.sex, 2);
bOK = fnd.Execute('${mz}', true, true, false, false, false, true, 0 , false, po.mz, 2);
bOK = fnd.Execute('${address}', true, true, false, false, false, true, 0 , false, po.address, 2);
var cell = doc.Tables(1).Cell(1,7);
cell.Range.InlineShapes.AddPicture(po.photo);
//Execute('${name}', true, true, false, false, false, true, WdFindWrap , false, name, wdReplaceAll, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl, MatchPrefix, MatchSuffix, MatchPhrase, IgnoreSpace, IgnorePunct);
}
</script>
</html>
相关文章推荐
- 今天把PHP程序与smarty完善了下,现在发过来大家给点建议!分别是模板中加了JS判断
- JS模板和JSON数据的结合
- node.js中结合redis实现session修改完善(2)
- 使用百度JS模板引擎生成PDF和Word文档
- doT.js 模板引擎的使用
- JS组件系列——基于Bootstrap Ace模板的菜单和Tab页效果分享(你值得拥有)
- [js高手之路]Node.js模板引擎教程-jade速学与实战3-mixin
- [js高手之路]Node.js模板引擎教程-jade速学与实战4-模板引用,继承,插件使用
- 前端周刊第47期:Vue.js 后台模板 + React Conf 2017 + 饿了么面试宝典
- poi导出word2003(动态数据,不用模板,且生成word能再次导入)
- js结合后台返回参数,动态控制各列数据展示
- 39行代码实现JS HTML模板(轻量+高效+易用)
- 下一代Jquery模板-----JsRender
- POI模板导出word
- java word 模板 数据填充
- java根据ftl模板生成word文档(列表)
- office2003安全模式启动,默认模板问题/打开word就显示“无法装载这个对象”
- word文档的多级次标题模板设置
- js 调用word模版 打印页面
- c#结合js实现无刷新省市联动菜单