Insert table into a document

Hello,
I want to insert a table into my document,what should I do?Thank you!

Hi Candy,
You can find the details of how to do this on the page here under “Inserting a table”.
If you have any troubles setting this up please feel free to ask and we will help.
Thanks,

Hi

Thanks for your inquiry. You can easily insert table into your document using DocumentBuilder. Please see the following code for more information.
https://reference.aspose.com/words/java/com.aspose.words/documentbuilder/#insertCell
Best regards.

Thank you for your reply,now I can insert a table into a document,but how can I set its borders?

Hi

Thanks for your inquiry. Just use CellFormat to configure borders and other settings of cells. Please see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set borders.
builder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
builder.write("Text in the merged cells.");
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("Text in one cell");
builder.endRow();
builder.insertCell();
// This cell is vertically merged to the cell above and should be empty.
builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("Text in another cell");
builder.endRow();
builder.endTable();
doc.save("C:\\Temp\\out.doc");

Best regards.

Thank you very much.I have another questions.
How can I insert formula or function into the document or tables?

Hi Candy,
Could you please elaborate on which type of formula you are looking for? An example would be useful as well.
Thanks,

Hi,
For example,There’s “UnitPrice” and “Quantity” columns in my table, and I want add the third column to show the total value of “UnitPrice*Quantity”? What should I do?
Thank you!

Hi Candy,
Thanks for the additional information.
You can insert a formula that achieves this by using the code below.

builder.StartTable();
builder.InsertCell();
builder.Write("2");
builder.InsertCell();
builder.Write("10");
builder.InsertCell();
builder.InsertField("=PRODUCT(LEFT)");
builder.EndRow();
builder.EndTable();

Thanks,

Hi ,
I use the code in the Java version,but it dosen’t worked well. Is it doesn’t support the Aspose word for Java?

Hi Candy,
My apologises, I forgot to add you should call doc.updateFields() before saving your document. This should update the field with the current total.
Thanks,

Hello,
I use the method you provided to me,but there’s another problem. The attchment is the screenshot.
I use the Java version.

Hi Candy,
Sorry, I mislead you, the UpdateFields() feature only updates fields such as this in the .NET version of Aspose.Words at the moment. We are working to syncronize the .NET and Java versions so this feature will be avaliable in Java as soon as this is complete. We will inform you about any developments regarding this.
In the mean time I suggest you handle any calculations of this kind through code by gathering the values in each cell of your table and calcuating the forumla through code and inserting the answer as plain text.
Thanks,