Detecting merged cells in a word document table
<p><strong>A little background</strong></p>

<p>I have a software specification which I need to parse requirements from in the form of tables. They are not always in the same format either. I inherited a python script that uses win32com to parse the word document, and then openpyxl to export the requirements to an excel file, which is then uploaded to HP ALM. </p>

<p><strong>Question</strong> </p>

<p>Using python (or some other language that can communicate with python), I am looking for a relatively simple and easy way to differentiate between merged cells, and empty cells (both of which occur in the microsoft word documents)(2010 .docx). </p>

<p><strong>Explanation</strong></p>

<p>So far, I have been searching for a solution to this for a couple weeks now, but I haven't found a satisfactory answer to the problem yet. </p>

<p>There are questions <a href="http://stackoverflow.com/questions/28559703/how-to-detect-merged-cells-in-vba-word-2010">here</a> and <a href="http://stackoverflow.com/questions/4523806/how-do-i-detect-a-word-table-with-horizontally-merged-cells">here</a> that I've looked at on stackoverflow. The second question says there is a field which will tell you whether there are merged cells in a table, which is a starting point, but not sufficient since it's possible the table will be one super long table spanning many pages.</p>

<p><strong>Attempts at a solution</strong></p>

<p><strong>Attempt 1.)</strong> My first thought was that surely win32com supports detecting merged cells in a table. So I searched and searched for methods that would do this for me. The only thing I found that would work is checking whether a merged cell is blank, while the previous one isn't. But, then I can't tell if the cell is truly blank or merged.</p>

<p><strong>Attempt 2.)</strong> My next thought was to add the feature to win32com using COM and the win32 API. But, I found COM is quite unwieldy, out-of-date now, and super undocumented and difficult to use. The same goes for the win32 API. Basically, I found this is more effort than it's worth to do.</p>

<p><strong>Attempt 3.)</strong> Then I began looking for alternative libraries to win32com, such as docx for python. The issue here, is that I work on a non-administrator computer, which severely restricts my ability to download third party libraries. Thus, I have yet to try this option, because I went down this road when getting win32com and openpyxl.</p>

<p><strong>Attempt 4.)</strong> My latest and possibly final attempt at figuring this out was to turn the word docx document into an XML file that I can parse easily. However, I don't know XML, nor do I know the standard format word uses for XML.</p>

<p>And here I am now looking for the quickest, cleanest, way to do this without rewriting libraries, or starting my 1000 line script over from scratch. (which by the way has a display GUI layed over the top of it, that's why it's so long)</p>

<p>According to <a href="https://msdn.microsoft.com/en-us/library/office/ff821310.aspx" rel="nofollow">the doc</a> merged cells in Word become one cell after being merged (<a href="https://msdn.microsoft.com/en-us/library/office/ff840729.aspx" rel="nofollow">unlike excel</a>). So the concept of merged cells do not really exists in Word. The only way to detect them will be to analyse all the tables with the algorithm you found in the posts linked in your question. Which consist on finding <em>missing</em> cells that do not exists because another cell is taking their place (which is the result of a merge).</p>

python vba ms-word win32com