这个只能在IE上用,使用jscript。
var WordApp=new ActiveXObject("Word.Application");
var wdCharacter=1
var wdOrientLandscape = 1
WordApp.Application.Visible=true;
var myDoc=WordApp.Documents.Add();
WordApp.ActiveDocument.PageSetup.Orientation = wdOrientLandscape
WordApp. Selection.ParagraphFormat.Alignment=1 //1居中对齐,0为居右
WordApp. Selection.Font.Bold=true
WordApp. Selection.Font.Size=20
WordApp. Selection.TypeText("我的标题");
WordApp. Selection.MoveRight(wdCharacter); //光标右移字符
WordApp.Selection.TypeParagraph() //插入段落 相当于br
WordApp. Selection.Font.Size=12
WordApp. Selection.TypeText("副标题"); //分行插入日期
WordApp.Selection.TypeParagraph() //插入段落
var myTable=myDoc.Tables.Add (WordApp.Selection.Range, 8,7) //8行7列的表格
var aa = "我的列标题"
for (i= 0;i<7;i++)
{
with (myTable.Cell(1,i+1).Range)
{
font.Size = 12;
InsertAfter(aa);
ColumnWidth =4;
ParagraphFormat.Alignment =1; //设置对齐方式 水平对齐
}
}
for (i =0;i<7;i++)
{
for (n =0;n<7 ;n++)
{
with (myTable.Cell(i+2,n+1).Range)
{
font.Size = 12;
InsertAfter("bbbb");
ParagraphFormat.Alignment =1; //设置对齐方式 水平对齐
}
}
}
myDoc .saveAs("d:\\gc.doc"); //保存word