Hello
I have some issues with tables.
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.
Thank you in advance
Jean-Pascal Lim
Hi Jean-Pascal,
Document doc = new
Document();<o:p></o:p>
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
Table table = builder.startTable();
builder.insertCell();
builder.endRow();
builder.endTable();
//builder.insertParagraph();
builder.writeln("test");
doc.save(MyDir + "Out.docx");
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. http://www.aspose.com/docs/display/wordsjava/Working+with+Merged+Cells
Hello Tahir.
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.
Thank you in advance
Jean-Pascal Lim
Hi Jean-Pascal,
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.Please read about Composition Diagrams and Document Tree Navigation from here:Moreover, please read about creation of table from following documentaion links. Hope this helps you.Regarding your second query, I am working over it and will update you asap.
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.
Document doc = new Document(MyDir + "test (11).docx");
//first table
Table table1 = (Table)doc.getChild(NodeType.TABLE, 0, true);
System.out.println( " preferedwidth : " + table1.getPreferredWidth());
System.out.println( " First Cell Width : " + table1.getFirstRow().getFirstCell().getCellFormat().getWidth());
//second table
Table table2 = (Table)doc.getChild(NodeType.TABLE, 1, true);
System.out.println( " preferedwidth : " + table2.getPreferredWidth());
System.out.println( " First Cell Width : " + table2.getFirstRow().getFirstCell().getCellFormat().getWidth());