Recently I heard of a term word Macro programming. I learned how to add a word table dynamically in js.
The Code is as follows:
Script
Function wordcontorl (){
Alert ("Baby Meng jia ");
Var WordApp = new ActiveXObject ("Word. Application ");
Var wdCharacter = 1
Var wdOrientLandscape = 1
WordApp. Application. Visible = true; // whether the generated word is displayed after the execution is complete
Var myDoc = WordApp. Documents. Add (); // create a new empty document
WordApp. ActiveDocument. PageSetup. Orientation = wdOrientLandscape // set the page direction to landscape
WordApp. Selection. ParagraphFormat. Alignment = 1 // 1 align, 0 is right
WordApp. Selection. Font. Bold = true
WordApp. Selection. Font. Size = 20
WordApp. Selection. TypeText ("Meng Jiaxiang ");
WordApp. Selection. MoveRight (wdCharacter); // move the cursor to the right
WordApp. Selection. TypeParagraph () // insert a paragraph
WordApp. Selection. Font. Size = 12
WordApp. Selection. TypeText ("----- "); // The Insert Date of the branch.
WordApp. Selection. TypeParagraph () // insert a paragraph
Var myTable = myDoc. Tables. Add (WordApp. Selection. Range, 8, 7) // table with 8 rows and 7 Columns
// MyTable. Style = "Grid"
Var aa = "Meng Jia title"
Var TableRange; // assign values to cells in the table
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 ("Meng Jia Xiaoxiao ");
}
}
}
Row_count = 0;
Col_count = 0
MyDoc. Protect (1)
}
Wordcontorl ()
Script
There are many implementation methods for each function. I hope you can share different ideas and methods. You can add QQ412546724. Haha