Create Ms Word doc using Javascript And vbscript

复制代码
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 
 4 <head>
 5 <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
 6 <title>Create Ms Word doc using Javascript </title>
 7 <meta name="Author" content="涂聚文" />
 8 <script type="text/javascript">
 9 var app =new ActiveXObject('Word.Application');// 
10 var objWord;
11 var docText;
12 objWord=app.Documents.Add();
13 app.Selection.GoTo(3,1,3,"");
14 var range = app.Selection.Range;//objWord.Range(0,0);
15 var WTable = objWord.Tables.Add(range, 3,3);
16 WTable.Cell(1,1).Range.Font.Name = "迷你繁篆体";
17 WTable.Cell(1,1).Range.Text = "塗聚文 Geovin Du";
18 WTable.Cell(1,2).Range.Font.Size = 18;
19 WTable.Cell(1,2).Range.Bold = true;
20 WTable.Cell(1,2).Range.Font.Italic = true;
21 WTable.Cell(1,2).Range.Font.Color = 5287936;
22 WTable.Cell(1,2).Range.Text = "塗聚文 天下為公";
23 WTable.Cell(2,1).Range.ParagraphFormat.Alignment = 1; // 0= Left, 1=Center, 2=Right
24 WTable.Cell(2,1).Range.Font.Name = "Arial";
25 WTable.Cell(2,1).Range.Font.Size = 12;
26 WTable.Cell(2,1).Range.Bold = false;
27 WTable.Cell(2,1).Range.ParagraphFormat.Alignment = 2;
28 WTable.Cell(3,3).Range.Font.Name = "宋体";
29 WTable.Cell(3,3).Range.Font.Size = 14;
30 WTable.Cell(3,3).Range.Bold = true;
31 WTable.Cell(3,3).Range.Font.Underline = true;
32 WTable.Cell(3,3).Range.ParagraphFormat.Alignment = 0;
33 WTable.Cell(3,2).Range.Text = "締友計算機信息技術有限公司 生活的意義,工作的意義";
34 app.Options.DefaultBorderLineStyle = 1;
35 app.Options.DefaultBorderLineWidth = 8;
36 WTable.Borders(-1).LineStyle = 1;
37 WTable.Borders(-2).LineStyle = 1;
38 WTable.Borders(-4).LineStyle = 1;
39 WTable.Borders(-6).LineStyle = 1;
40 WTable.Borders(-3).LineStyle = 1;
41 WTable.Borders(-5).LineStyle = 1;
42 WTable.Borders(-5).Color = 5287936;
43 app.ActiveDocument.SaveAs("c:\geovindujavaScript1.doc");//保存
44 docText = objWord.Content;
45 //objWord.SaveAs("c:\geovindujavaScript1.doc"); //此方法也可以
46 document.write(docText);//把Word內容空顯示在網頁
47 app.Application.Printout(); //调用自动打印功能  
48 app.Quit();
49 
50 </script>
51 </head>
52 
53 <body>
54 
55 </body>
56 
57 </html>
复制代码

 

复制代码
 1 <script type="text/vbscript">
 2 'Geovin Du
 3 Set objWord = CreateObject("Word.Application")
 4 objWord.Caption = "Test Caption"
 5 objWord.Visible = True
 6 Set objDoc = objWord.Documents.Add()
 7 Set objSelection = objWord.Selection
 8 
 9 objSelection.Font.Name = "Arial"
10 objSelection.Font.Size = "18"
11 objSelection.TypeText "Network Adapter Report"
12 objSelection.TypeParagraph()
13 
14 objSelection.Font.Size = "14"
15 objSelection.TypeText "" & Date()
16 objSelection.TypeParagraph()
17 objSelection.TypeParagraph()
18 
19 objSelection.Font.Size = "10"
20 Set table1 = objSelection.Tables.Add(objSelection.Range, 2, 4)  
21   
22 'Set Table1 = objDoc.Tables(1)  
23 rowcount = Table1.Rows.Count  
24 For i = 1 To Table1.Rows.Count  
25     For j = 1 To Table1.Columns.Count  
26         '在单元格i,j里填充内容  
27         Table1.Cell(i, j).Range.Text = "" & i & "" & j & ""  
28         '为单元格i,j添加书签  
29         Table1.Cell(i, j).Range.Bookmarks.Add "书签" & i & "行," & j & ""  
30     Next  
31 Next 
32 objDoc.SaveAs("C:\geovindutestdoc.doc")
33 objWord.Quit
34 </script>
复制代码

 

posted @   ®Geovin Du Dream Park™  阅读(435)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
< 2012年8月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示