We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cell gridSpan

How do I retrieve a cell’s gridSpan without access to <w:gridSpan> node? I have enclosed 2 docx files; each with a table.


In Doc1.docx, the first row contains 4 cells, with the last 2 cells spanning 3 cells each. Each following rows contains 8 cells.

In Doc2.docx, the first row contains 1 cell, spanning 7 cells. The following row contains 3 cells, with the last 2 cells spanning 3 cells each. The remaining rows, contain 7 cells.


How do I retrieve a cell’s gridSpan without access to <w:gridSpan> node? I have enclosed 2 docx files; each with a table.


In Doc1.docx, the first row contains 4 cells, with the last 2 cells spanning 3 cells each. Each following rows contains 8 cells.

In Doc2.docx, the first row contains 1 cell, spanning 7 cells. The following row contains 3 cells, with the last 2 cells spanning 3 cells each. The remaining rows, contain 7 cells.

Hi Justin,


Thanks for your inquiry. Please read the following documentation link to work with merged cells.
http://www.aspose.com/docs/display/wordsjava/Working+with+Merged+Cells

Moreover, please note that a table in MS Word is a set of independent rows. Each row has a set of cells independent on cells of other rows. So there is no logical “column” in a MS Word’s table. “The 1st column” is something like “a set of the 1st cells of each row in a table”.

For example, it’s possible to have a table where the 1st row consists of two cells: 2cm and 1cm and the 2nd row consists of different two cells: 1cm and 2cm of width.

Hope this answers your query. Please let us know if you have any more queries.

Using the code in the link you have provided, does not help. It tells me that the cells are not merged.


I am trying to convert these tables to an HTML equivalent table and finding it hard to do so without the gridSpan variable.








Hi Justin,


Thanks for your inquiry.

justin.murray:

Using the code in the link you have provided, does not help. It tells me that the cells are not merged.

Please note that a table in MS Word is a set of independent rows. Each row has a set of cells independent on cells of other rows. So there is no logical “column” in a MS Word’s table. “The 1st column” is something like “a set of the 1st cells of each row in a table”.

For example, it’s possible to have a table where the 1st row consists of two cells: 2cm and 1cm and the 2nd row consists of different two cells: 1cm and 2cm of width.

Please check following code snippet. This code example set the table’s cell width instead of merging Cells. Hope this answers your query.

//Create Document and DocumentBuilder<o:p></o:p>

Document doc = new Document();<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);<o:p></o:p>

//Build table<o:p></o:p>

builder.insertCell();<o:p></o:p>

builder.write(“first column”);<o:p></o:p>

//specify width of cell<o:p></o:p>

builder.getCellFormat().setWidth(250);<o:p></o:p>

builder.endRow();<o:p></o:p>

//note that in the next row you should also specify width of each cell<o:p></o:p>

//Build table<o:p></o:p>

builder.insertCell();<o:p></o:p>

builder.write(“first column”);<o:p></o:p>

//specify width of cell<o:p></o:p>

builder.getCellFormat().setWidth(50);<o:p></o:p>

builder.insertCell();<o:p></o:p>

builder.write(“Second column”);<o:p></o:p>

builder.getCellFormat().setWidth(200);<o:p></o:p>

builder.endRow();<o:p></o:p>

builder.endTable();<o:p></o:p>

doc.save(MyDir + “out.doc”);


justin.murray:

I am trying to convert these tables to an HTML equivalent table and finding it hard to do so without the gridSpan variable.

I have converted the shared MS Word documents to html and have not found any issue with column span. It would be great if you please share some more detail about your query. We will then provide you more information on this along with code.



Unfortunately, the tables in the word document are already built and can not be changed. Nor can I convert the document to HTML as a whole. I am trying to extract just the table and information needed to construct an HTML table at a later point.

Hi Justin,


Thanks for your inquiry.

As Tahir has pointed out in his article, it is not always possible to ascertain if certain. Microsoft Word simply does not write this data at times and instead writes wide cells.

Furthermore HorizontalMerge and VerticalMerge it is not the same as GridSpan. If you try opening .xml file of Docx document you will see hMerge (Horizontally MergedCell) and vMerge (Vertically Merged Cell) elements which are responsible for merged cells. Grid and GridSpan are kind of helpers for MS Word to render tables faster. Grid and GridSpan are optional. They can be omitted that is why we cannot rely on them upon reading merge information from loaded documents. In other words the GridSpan attribute being present does not mean than corresponding cells are merged.

Is there any problem with converting the table to HTML using Aspose.Words directly?

Cheers,