%% Read Specific Table from Microsoft Word Document
% The readtable function, by default, reads the first table from a Microsoft Word document file. The file MaintenanceReport.docx contains two tables. The last row of the second table contains a cell with merged columns that do not match the table variables.
% Read the second table by setting the TableIndex option to 2. To skip rows that have cells with merged columns, set the MergedCellColumnRule option to 'omitrow'.

filename = "MaintenanceReport.docx";
T = readtable(filename,'TableIndex',2,'MergedCellColumnRule','omitrow')

% Alternatively, you can select a table using an XPath selector using the TableSelector option. To select the Microsoft Word document table that contains the text "Description", use the XPath selector "//w:tbl[contains(.,'Description')]".

T = readtable(filename, ...
    'TableSelector',"//w:tbl[contains(.,'Description')]", ...
    'MergedCellColumnRule','omitrow')

% Copyright 2021 The MathWorks, Inc.