Microsoft Word connector methods

  • Release version: Washingtondc
  • Updated February 1, 2024
  • 8 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of Microsoft Word Connector Methods

    The Microsoft Word connector methods facilitate automation of various tasks within Microsoft Word documents, enabling more efficient document management and processing. This set of methods allows you to open, modify, and save Word files, among other operations.

    Show full answer Show less

    Key Features

    • Open: Opens a Word document from a specified local filepath, which is required before using other methods.
    • AddFooter: Adds a footer to the document; requires the document to be opened first.
    • AddHeader: Inserts a header into the document after opening it.
    • ExportToPDF: Converts the Word document to a PDF format, needing the document to be opened initially.
    • CellCopy and CellPaste: Copy and paste functionalities for table cell content, requiring the SetTable method to be executed beforehand.
    • DeletePage, DeleteRow, and DeleteColumn: Remove specified elements from the document, requiring the Open or SetTable methods as a prerequisite.
    • GetTable: Retrieves data from a specified table in the document, allowing for further data manipulation.
    • InsertText: Inserts text at the beginning of the document.
    • Save and SaveAs: Save changes to the document or save it under a new name.

    Key Outcomes

    By utilizing these methods, ServiceNow customers can automate and streamline their document processing tasks in Microsoft Word, resulting in increased productivity and accuracy. Customers can expect to effectively manage document content, structure, and format through a series of well-defined operations, ultimately enhancing their workflow efficiency.

    The Microsoft Word connector methods enable you to perform various day-to-day tasks with Microsoft Word documents and automate them. For example, add a page footer.

    Open

    Opens a Microsoft Word file saved on the local disk.
    Note:
    You must execute this method before executing any other method on the Microsoft Word connector.
    Table 1. Open method parameters
    Parameter Description Data port type Data type Default value Mandatory?
    Filepath Specifies the path to the Microsoft Word file in the local disk. Data in String No default value Yes
    Timeout Specifies the time after which the operation times out. Data in Integer No default value No
    Password Use a password if the document is password protected. Data in String None No
    Return Returns the boolean value based on the outcome of the operation. If True, the file is opened. Else, if False, the file failed to open. Data out Boolean Not applicable Not applicable

    For details on the issues related to the Open method, see KB article KB1123558 and KB article KB1123548.

    AddFooter

    Adds a footer to the Microsoft Word document.
    Note:
    You must execute the Open method before executing this method.
    Table 2. AddFooter method parameters
    Parameter Description Data port type Data type Default value Mandatory? Notes
    Text Specifies the text in the footer. Data in String No default value Yes
    FontSize Specifies the font size of the footer. Data in Integer No default value Yes

    To provide inputs, see Configure port properties

    AddHeader

    Adds a header to a Microsoft Word document.
    Note:
    You must execute the Open method before executing this method.
    Table 3. AddHeader method parameters
    Parameter Description Data port type Data type Default value Mandatory? Notes
    Text Specifies the text in the header. Data in String No default value Yes
    FontSize Specifies the font size of the header. Data in Integer No default value Yes

    CellCopy

    Copies the content of a table cell in a Microsoft Word document.
    Note:
    You must execute the SetTable method before executing this method.
    Input
    RowIndex, ColumnIndex

    CellPaste

    Pastes the copied table cell content into a table cell in a Microsoft Word document.
    Note:
    You must execute the CellCopy method before executing this method.
    Input
    RowIndex, ColumnIndex

    Close

    Closes the last opened Microsoft Word document.
    Note:
    You must execute the Open method before executing this method.
    Table 4. Close method parameters
    Parameter Description Data port type Data type Default value Mandatory? Notes
    saveChanges Specifies the Boolean value to save or close the document without saving the changes. If True, the changes are saved. Else, if False, the changes are not saved. Data in Boolean No default value Yes

    DeleteColumn

    Deletes a column from a table based on the specified index value of the column in a Microsoft Word document.
    Note:
    You must execute the SetTable method before executing this method.
    Input
    ColumnIndex

    DeletePage

    Deletes a page from a Microsoft Word document.
    Note:
    You must execute the Open method before executing this method.
    Table 5. DeletePage method parameters
    Parameter Description Data port type Data type Default value Mandatory? Notes
    PageIndex Specifies the index number of the page that the method deletes. Data in Integer No default value No If you don't provide any index number, the method deletes the first page by default.

    DeleteRow

    Deletes a row from a table based on the specified index value of the column in a Microsoft Word document.
    Note:
    You must execute the SetTable method before executing this method.
    Input
    RowIndex

    DeleteTable

    Deletes a table from a Microsoft Word document.

    If the document has multiple tables, the method deletes the first table in the document.

    Note:
    You must execute the SetTable method before executing this method.

    ExportToPDF

    Exports a Microsoft Word document to a PDF document.
    Note:
    You must execute the Open method before executing this method.
    Table 6. ExportToPDF method parameters
    Parameter Description Data port type Data type Default value Mandatory? Notes
    Filepath Specifies the path to the location where the Word document is exported to PDF. Data in String No default value Yes

    Find

    Finds the text you specify in a Microsoft Word document and returns a Boolean response.
    Input
    Text
    Output
    Return (Boolean)

    GetCellValueByIndex

    Returns the value in a cell of a table in a Microsoft Word document.
    Input
    CellIndex

    GetFooterText

    Returns the content of the footer in a Microsoft Word document.

    Note:
    You must execute the Open method before executing this method.
    Output
    Return (String)

    GetHeaderText

    Returns the content of the header in a Microsoft Word document.

    Note:
    You must execute the Open method before executing this method.
    Output
    Return (String)

    GetPageCount

    Returns the number of pages in a Microsoft Word document.

    Output
    Return (Integer)

    GetRowIndexByValue

    Returns the row index value of a row based on the value in the row.
    Note:
    You must execute the GetTable and SetTable methods before executing this method.
    Input
    Table, Value

    GetTable

    Returns the data in a table of a Microsoft Word document as a table object and data table. If the document contains multiple tables, you can specify the table index to identify the table for the method. You can also specify the table type, if needed.

    Depending on the table structure, you can optionally configure the table type for the method. To configure the table, do the following steps.
    1. Click the method settings icon (Method settings icon.).
    2. Select the table type.
    3. Click OK.

    GetTableCellValues

    Returns the values in one or more table cells.

    To specify the number of cells, you must configure the index values of the cells. To configure, do the following.
    1. Click the method settings icon (Method settings icon.).
    2. Click (Click to add cell index icon.).
    3. Enter the index values for the cells.
    4. Repeat the steps to add more index values.
    5. Click OK.
    Output
    Cell Index (Object)

    GetTableCount

    Returns the number of tables in a Microsoft Word document. You can optionally specify the type of table for the method to identify.

    To configure the type of table, do the following steps.
    1. Click the method settings icon (Method settings icon.).
    2. Select the table type.
    3. Click OK.
    Output
    Return (Integer)

    GetTableRowData

    Returns the values in one or more cells of a row in a Microsoft Word document. You can specify the index values of the cells of the row.

    You can configure the index values of the cells in a row. To configure, do the following steps.
    1. Click the method settings icon (Method settings icon.).
    2. Click the add index value icon (Add index value icon.).
    3. Enter the index value of the cell.
    4. Repeat the steps to add more index values.
    5. Click OK.

    GetText

    Returns all the text content in a Microsoft Word document.

    Table 7. GetText method parameters
    Parameter Description Data port type Data type Default value Mandatory? Notes
    Return Returns the text from the Word document. Data Out String No default value Not applicable

    InsertNewColumn

    Inserts a new column in the first table in the document based on the index value of the column you specify.
    Input
    ColumnIndex

    InsertNewRow

    Inserts a new row based on the index value.
    Input
    RowIndex

    InsertPicture

    Inserts an image.
    Input
    ImageFilePath
    Bookmark

    InsertTable

    Inserts a table into a Microsoft Word document. Inserts a table into a Microsoft document. You can optionally customize the document by configuring it before inserting.

    Note:
    Before executing this method, you must execute the GetTable and SetTable methods.
    To customize the table before inserting, do the following steps.
    1. Click the method settings icon(Method settings icon.).
    2. Select Include Headers.
    3. Select border style and autofit behavior.
    4. Select Include Empty Rows.
    5. To ignore specific columns, click the add index value icon (Add index value).
    6. Enter the index value of the column.
    7. Click OK.
    Input
    Bookmark
    Data

    InsertText

    Inserts text in the beginning of the Word document.

    Table 8. InsertText method parameters
    Parameter Description Data port type Data type Default value Mandatory? Notes
    text Takes the text. Data In String No default value Yes

    IsOpen

    Checks whether a Microsoft Word document is open.

    Output
    Return (Boolean)

    MergeByCellIndices

    Merges the range of cells specified in the form of index value range.
    Input
    StartCellIndex EndCellIndex

    MergeByRowCol

    Merges a range of cells of a table in a Microsoft Word document.
    Input
    StartRowIndex StartColIndex EndRowIndex EndColIndex

    ReplaceBookmark

    Replaces a bookmark in a Microsoft Word document with the specified text.
    Input
    Bookmark ReplaceText

    ReplaceBookmarks

    Finds and replaces multiple bookmarks in a Microsoft Word document with the specified text.
    Input
    Text
    Provide more details of the bookmark text to replace as follows:
    1. Double-click the component.
    2. In the PROVIDE LABELS/BOOKMARKS dialog box, click the click to add label icon (Click to add label icon.) and enter the bookmark to replace it.

      Repeat this step to add more bookmarks.

    3. Click OK.

    ReplaceFooterText

    Finds and replaces the footer text in a Microsoft Word document with the specified text.
    Input
    FindText
    ReplaceText

    ReplaceHeaderText

    Finds and replaces the header text in a Microsoft Word document with the specified text.
    Input
    FindText
    ReplaceText

    ReplaceStaticText

    Finds and replaces the text in a Microsoft Word document with the specified text. Replaces bookmarks, headings, or any text based on the configuration.

    You must configure the method before executing. To configure, do the steps.
    1. Click the method settings icon (Method settings icon.).
    2. Click the add text icon (Add text icon.)
    3. Enter the heading, bookmark, or text that you want to replace.
    4. Repeat the steps to enter more text.
    5. Click OK.
    Input
    Object

    ReplaceText

    Finds and replaces the text in a Microsoft Word document with the specified text.
    Input
    FindText
    ReplaceText

    Resize

    Resizes the window of a Microsoft Word document.
    Input
    Left
    Top
    Width
    Height

    Save

    Saves the opened Microsoft Word document.

    SaveAs

    Saves the opened Microsoft Word document with the specified file name.
    Input
    Filepath

    SetTable

    Sets a table in a Microsoft Word document.
    Input
    Table

    SetTableCellValues

    Sets the content of a table cell in a Microsoft Word document.

    Provide one or more cell indexes and value types as follows:
    1. Double-click the component.
    2. In the PROVIDE CELL INDEXES dialog box, click the click to add cell index icon (Click to add cell index icon.) and enter a cell index and select a value type.

      Repeat this step to add more cell indexes and value types.

    3. Click OK.

    SetTableRowData

    Sets the content in a table row in a worksheet of a Microsoft Word document.
    Input
    RowIndex
    Provide the column index as follows:
    1. Double-click the component.
    2. In the PROVIDE COLUMN INDEXES dialog box, click the click to add cell index icon (Click to add cell index icon.) and enter a column index.
    3. Click OK.