復制代碼 代碼如下:
<script>
function wordcontorl(){
alert("小孟佳的寶貝");
var WordApp=new ActiveXObject("Word.Application");
var wdCharacter=1
var wdOrientLandscape = 1
WordApp.Application.Visible=true; //執行完成之後是否彈出已經生成的word
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() //插入段落
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("孟佳小可愛");
}
}
}
row_count = 0;
col_count = 0
myDoc.Protect(1)
}
wordcontorl()
</script>
每種功能的實現方法有很多,希望各位可以交流不同的思想和方法。可以加QQ412546724。呵呵