javascript教程動態給word doc文檔增加表格
<script>
function wordcontorl(){
alert("小孟佳的寶貝");
var WordApp=new ActiveXObject("Word.Application");
var wdCharacter=1
var wdOrientLandscape = 1
WordApp.Application.Visible=true; //執行完成之後是否彈出已經生成的word
va r 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() //插入段落
WordApp. Selection.Font.Size=12
WordApp. Selection.TypeText("-----朱漪編寫"); 分行插入日期
WordApp.Selection.TypeParagraph() //插入段落
var myTable=myDoc.Tables.Add (WordApp.Selection.Range, 8,7) //8行7列的表格
//myTable.Style="網格型"
var aa = "孟佳標題"
var TableRange; //以下為給表格中的儲存格賦值
for (i= 0;i<7 ;i++)
{
with (myTable.Cell(1,i+1). Range)
{
font. Size = 12;
InsertAfter(aa);
ColumnWidth =4
}
}
for (n =0;n<7;n++)
{
for (i =0;i<7 ;i++)
{
with (myTable. Cell(i+2,n+1). Range)
{font. Size = 12;
InsertAfter(www.jzread.com);
}
}
}
row_count = 0;
col_count = 0
myDoc.Protect(1)
}
wordcontorl()
</script>