none
API JavaScript for word 2013 RRS feed

  • Question

  • Hi,

    I was using a .js file to generate Word documents.

    But recently, my company has improved MS Office from 2010 to 2016, including the update of JavaScript API for Word.

    It's fun and better but my .JS script does not work, in particular the management of tables in Word.

    The job expected is:

    1. When the selection is in a table, it gets the row number.
    2. it selects the row,
    3. it copy the row,
    4. it inserts a row after
    5. it paste on new row.

    I try something like this, but it doesn't work :

    var row = wordApp.selection.information(wdEndOfRangeRowNumber); //
    wordApp.selection.tables(1).rows(row).select();
    wordApp.selection.tables(1).rows(row).copy();
    wordApp.selection.tables(1).insertrowsbelow();
    wordApp.selection.tables(1).rows(row + 1 ).paste();

    Someone can help me?

    Thx a lot.

    Tuesday, March 22, 2016 1:29 PM

Answers

  • >>>But recently, my company has improved MS Office from 2010 to 2016, including the update of JavaScript API for Word.

    It's fun and better but my .JS script does not work, in particular the management of tables in Word.<<<

    According to description, you are using client-side code that launches and automates Microsoft Office Word, and JavaScript API for Word do not support these operation. So I suggest that you could  refer to below code:
    <script type="text/javascript">
        function CreateDocument() {
            // Start a new instance of Microsoft Word
            var oApplication = new ActiveXObject("Word.Application");
            oApplication.Visible = true;
    
            var oDoc = oApplication.documents.add();
    
            var range = oApplication.ActiveDocument.Range(0, 0)
    
            oApplication.ActiveDocument.tables.Add(range, 3, 4)
            oApplication.Selection.Tables(1).Style = "Table Grid"
    
            //wdEndOfRangeRowNumber
            var row = oApplication.selection.information(14);
    
    
            oApplication.selection.tables(1).rows(row).select();
            oApplication.selection.tables(1).rows(row).Range.copy();
            oApplication.Selection.insertrowsbelow();
            oApplication.selection.tables(1).rows(row + 1).Range.paste();
    
        }
    </script>


    Wednesday, March 23, 2016 8:04 AM