Insert dynamic row column in table

@tahir.manzoor

Thank you for your support. In my case I implemented the different solution but your provided solution helped me a lot to build that.
There is one issue, As I am adding my new table in existing table row where my input token present so there is one extra new line gets added. I gone throw with different solution but I didn’t found anything which solve my problem. Do you have any idea about this?
I can’t use row.remove() method as that single row contains my whole table which I want in output.
I have attached one doc for your reference. Reference Doc.PNG (4.0 KB)

@vke3,

Thanks for your inquiry. Please share your output document that shows the undesired behavior. We will then share the code example according to your requirement.

@tahir.manzoor,

Sharing the Output table image Output.PNG (56.6 KB)

And can we change the font of table cell content? After generation of doc its changing my font from Arial to caliber

@vke3,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

@tahir.manzoor,

I have already shared the input and expected output file along with the output I am getting. Can’t share the whole source code as it’s too big and too many flow. but in first massage i.e. in Info.zip I have shared the table formation method with you and how I am inserting the two docs which gives the idea of implementation. Thanks you.

@vke3,

Thanks for your inquiry. You shared two .zip files in this thread. The first ZIP file contains the screenshot of output document. For second ZIP file, we share the code example in this thread.

For this issue, we need your input, output and expected output documents. Please share the documents for investigation. We will then provide you more information about your query.

@tahir.manzoor,

Please find the attached document templates. Files.zip (47.4 KB)

@vke3,

Thanks for sharing the detail. Unfortunately, we have not found the output document that shows the undesired behavior in the ZIP file.

In your case, we suggest you please iterate over the table’s row after generating the table and remove the Row node that has no text inside. You can use Row.toString(SaveFormat.TEXT) method to get the text of table’s row and remove the row using Row.remove() method.

If you still face problem, please attach the output Word file that shows the undesired behavior. We will then share the code example according to your requirement.

@tahir.manzoor,

There is a file named “Output_Which_I_am_getting.png” which shows the undesired behavior. I have highlighted the part also.
I can’t use the row.remove() mehod to remove the row, as I am adding the table inside the one row of the table.( mentioned in ReadMe.txt file in the Zip).
In short suppose I have a table with number of rows 5. And after 3rd row I have to add some extra 2/3 rows. In my case I don’t have the input template further in my process. I just have the position of the row. So I am creating a required table in some other document and inserting that document(table content) to the original template( i.e inside the 3rd row of our input table). So If I try to remove the 3rd row ( which has a content of my added new table) it will remove all my dynamically added rows. In this case I don’t want to remove the row, I want to remove that space in row which I highlighted in output image.

@vke3,

Thanks for sharing the detail. Unfortunately, it is difficult to say what the problem is without problematic output Word document and code example to reproduce this issue. To ensure a timely and accurate response, please attach the requested detail here for testing. We will investigate the issue and provide you modified code example.

@tahir.manzoor,

Please find the attachment. As I mentioned earlier, I have shared the methods of code. Can’t share the whole running code as the process is big(Rather compile java files). So shared the methods with you which will help you to understand the flow. As mentioned earlier, I have tokens in my input template and I am processing that token and getting data and creating output doc/pdf from that data. you can compare the Input template and output template for the sameFiles.zip (54.1 KB)

@vke3,

Thanks for sharing the document. In your document, there is an empty paragraph before the nested table. You can remove this paragraph using the following code snippet. Hope this helps you.

Document doc = new Document(MyDir + "PLD_SZ8 Product Legacy 2015-11-2_B_Draft.docx");
NodeCollection tables = doc.getChildNodes(NodeType.TABLE, true);
for (Table table : (Iterable<Table>) tables)
{
    if(table.getAncestor(NodeType.CELL) != null && table.getPreviousSibling() != null
            && table.getPreviousSibling().getNodeType() == NodeType.PARAGRAPH
            && table.getPreviousSibling().toString(SaveFormat.TEXT).trim().length() == 0)
    {
        table.getPreviousSibling().remove();
    }
}
doc.save(MyDir + "18.9.docx");

@tahir.manzoor,

This is what I was looking for :slight_smile:
It worked in my scenario. Thanks a lost for your continuous support. :+1:

@tahir.manzoor,

Hi, I am facing some issues, one of them is adding image to Documentbuilder.
I tried few ways to add the shape, however it’s not getting added in doc. The Image frame is getting added in docx file but not the Image. Could you please suggest the root cause and solution for this?
There is one more issue. Many time I build the table in Aspose and it works fine, but I am trying to build one more table which is not building properly. It just build the table header not the below rows ( won’t even get the exception or error ). I was not able to find the root cause ( you can check the section 6.1- 6.8 in shared undesired docx file for table).
Sharing the tried ways ( code snippet) and the undesired behavior output file.
File.zip (151.5 KB)

@vke3,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please attach the image file that you want to insert into document.
  • Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

@tahir.manzoor,

I have shared you all the files for both table issue and the image issue.
Image issue I solved with some other implementation. Could you please check the table related issue?
Well If I write the simple java method to get the table it will work. I have already created many tables. I have used some other API which is not the java API and hence the code is not compiling at your side as you don’t have the respective jars. Simple java code for table formation will work no doubt. Shared the same details with you. Could you please check what exactly causing problem to add the rows in table (with my code).
File.zip (91.5 KB)
Thanks,

@vke3,

Thanks for your inquiry. You have shared the images instead of problematic and expected output Word documents. If you do not share these documents, we will not be able to investigate your issue and provide you information about your issue.

@tahir.manzoor,

PLD_SZ8 Product Legacy 2015-11-2_B_Draft.docx it self is the problematic doc which I have shared with you in zip file. Whatever the problematic Image I have shared with you is from the same doc (PLD_SZ8 Product Legacy 2015-11-2_B_Draft.docx) just for your reference to know where is the exactly problem in doc.
Please check the section 6.1-6.8 in this doc. you can see the single row of the table in this doc( with the column name owner, assignee etc). And I am trying to add the below row of this heading row which is not getting added in my case.
Thanks.

@tahir.manzoor,

solved the table issue too. thanks.

@vke3,

It is nice to hear from you that you have solved your issue. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.