First, when creating a table, aspose seems to generate an empty line just after this one (in Times New Roman 12). This is quite non convenient.
For example, here is my code :
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
Table table = builder.startTable();
builder.insertCell();
builder.endRow();
builder.endTable();
builder.insertParagraph();
builder.write("test");
After saving, right after the table, there is an empty paragraph, and below that, my paragraph containing my “test” run. How can I prevent this “ghost” paragraph from appearing ?
Secondly, when I load a Word document with a merged cell , I don’t get any data about that cell in Aspose. If the cell has a specified size, I can get the size of the cell and I have some data to analyze. However, if the cell size is not filled, I don’t have any data to analyze !
That is surprising because, when I open the document.xml file from the document, I can see this tag : <w:gridSpan w:val=“3”/> This is the data I am looking for in the Aspose model. I would like to have a way to get this information.
Thanks for your inquiry. The DocumentBuilder.insertParagraph method inserts a paragraph break into the document. Please use DocumentBuilder.writeln method instead of insertParagraph as shown in following code snippet.
If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate as to how you want your final Word output be generated like. We will then provide you more information on this along with code.
Regarding your second query, 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.
Moreover, please read following documentation link for your kind reference. https://docs.aspose.com/words/java/working-with-merged-cells/
I am trying the provided method for the first point. I quite don’t like it because I would prefer a lot more the “insert paragraph” and “write” operations being separated.
The main problem is that when I load such a document, I get a Table Node, then a Paragraph Node. But when creating, I just need to create a Table and not the Paragraph.
For the second point, I am completely aware that columns don’t really exist in Word. However, cells size is not filled everytime. I provide you an example. The cells don’t have any size. Neither preferred size. And the table doesn’t have a size either.
If you look the first table,the cell of the first row is a merged cell. Right now, I don’t get any data telling me that this cell is merged : its size is 0, and its MergeType attribute is NONE.
So, if I want to recreate such a table, I can’t. All I know about the first row is the fact it has only one cell. I don’t know by any way that it’s a merged cell.
It is even more tricky with the second table.
The first two cells of the second row are merged. But again, the size is 0. So when I recreate the table, I only create 5 identical cells without any size (because I only get 0 as size when loading).
I really need a method which returns at least the number of cells in a merged cell.
*jplim:
I am trying the provided method for the first point. I quite don’t like it because I would prefer a lot more the “insert paragraph” and “write” operations being separated.
The main problem is that when I load such a document, I get a Table Node, then a Paragraph Node. But when creating, I just need to create a Table and not the Paragraph.
Unfortunately, I have not understood your query. It would be great if you please share what exact you want to achieve by using Aspose.Words. We will then provide you more information about your query along with code.
jplim:
If you look the first table,the cell of the first row is a merged cell. Right now, I don’t get any data telling me that this cell is merged : its size is 0, and its MergeType attribute is NONE.
So, if I want to recreate such a table, I can’t. All I know about the first row is the fact it has only one cell. I don’t know by any way that it’s a merged cell.
The width type of tables is ‘Auto’, this is the same as having no preferred width set. In this case size of the element is calculated using one of the other elements belonging to table which does have a size set. The size of cells is not 0, please try following code snippet.