I want to insert a table into my document,what should I do?Thank you!
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 for your inquiry. You can easily insert table into your document using DocumentBuilder. Please see the following code for more information.
Thank you for your reply,now I can insert a table into a document,but how can I set its borders?
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");
Thank you very much.I have another questions.
How can I insert formula or function into the document or tables?
Could you please elaborate on which type of formula you are looking for? An example would be useful as well.
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?
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();
I use the code in the Java version,but it dosen’t worked well. Is it doesn’t support the Aspose word for Java?
My apologises, I forgot to add you should call doc.updateFields() before saving your document. This should update the field with the current total.
I use the method you provided to me,but there’s another problem. The attchment is the screenshot.
I use the Java version.
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.