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>