Dynamic addition of code to jsword tables _ javascript skills

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.