Create Ms Word doc using Javascript And vbscript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Create Ms Word doc using Javascript </title>
<meta name="Author" content="涂聚文" />
<script type="text/javascript">
var app =new ActiveXObject('Word.Application');// 
var objWord;
var docText;
objWord=app.Documents.Add();
app.Selection.GoTo(3,1,3,"");
var range = app.Selection.Range;//objWord.Range(0,0);
var WTable = objWord.Tables.Add(range, 3,3);
WTable.Cell(1,1).Range.Font.Name = "迷你繁篆体";
WTable.Cell(1,1).Range.Text = "塗聚文 Geovin Du";
WTable.Cell(1,2).Range.Font.Size = 18;
WTable.Cell(1,2).Range.Bold = true;
WTable.Cell(1,2).Range.Font.Italic = true;
WTable.Cell(1,2).Range.Font.Color = 5287936;
WTable.Cell(1,2).Range.Text = "塗聚文 天下為公";
WTable.Cell(2,1).Range.ParagraphFormat.Alignment = 1; // 0= Left, 1=Center, 2=Right
WTable.Cell(2,1).Range.Font.Name = "Arial";
WTable.Cell(2,1).Range.Font.Size = 12;
WTable.Cell(2,1).Range.Bold = false;
WTable.Cell(2,1).Range.ParagraphFormat.Alignment = 2;
WTable.Cell(3,3).Range.Font.Name = "宋体";
WTable.Cell(3,3).Range.Font.Size = 14;
WTable.Cell(3,3).Range.Bold = true;
WTable.Cell(3,3).Range.Font.Underline = true;
WTable.Cell(3,3).Range.ParagraphFormat.Alignment = 0;
WTable.Cell(3,2).Range.Text = "締友計算機信息技術有限公司 生活的意義,工作的意義";
app.Options.DefaultBorderLineStyle = 1;
app.Options.DefaultBorderLineWidth = 8;
WTable.Borders(-1).LineStyle = 1;
WTable.Borders(-2).LineStyle = 1;
WTable.Borders(-4).LineStyle = 1;
WTable.Borders(-6).LineStyle = 1;
WTable.Borders(-3).LineStyle = 1;
WTable.Borders(-5).LineStyle = 1;
WTable.Borders(-5).Color = 5287936;
app.ActiveDocument.SaveAs("c:\geovindujavaScript1.doc");//保存
docText = objWord.Content;
//objWord.SaveAs("c:\geovindujavaScript1.doc"); //此方法也可以
document.write(docText);//把Word內容空顯示在網頁
app.Application.Printout(); //调用自动打印功能  
app.Quit();

</script>
</head>

<body>

</body>

</html>

<script type="text/vbscript">
'Geovin Du
Set objWord = CreateObject("Word.Application")
objWord.Caption = "Test Caption"
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection

objSelection.Font.Name = "Arial"
objSelection.Font.Size = "18"
objSelection.TypeText "Network Adapter Report"
objSelection.TypeParagraph()

objSelection.Font.Size = "14"
objSelection.TypeText "" & Date()
objSelection.TypeParagraph()
objSelection.TypeParagraph()

objSelection.Font.Size = "10"
Set table1 = objSelection.Tables.Add(objSelection.Range, 2, 4)  
  
'Set Table1 = objDoc.Tables(1)  
rowcount = Table1.Rows.Count  
For i = 1 To Table1.Rows.Count  
    For j = 1 To Table1.Columns.Count  
        '在单元格i,j里填充内容  
        Table1.Cell(i, j).Range.Text = "第" & i & "行" & j & "列"  
        '为单元格i,j添加书签  
        Table1.Cell(i, j).Range.Bookmarks.Add "书签" & i & "行," & j & "列"  
    Next  
Next 
objDoc.SaveAs("C:\geovindutestdoc.doc")
objWord.Quit
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值