We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Mail Merge Create MS Word Table

Hi - I use mailmerge tags to create word documnts. I need to populate a table with a given result set. So far I can do this by inserting a one row table the tablestart and tableend tags (and inside the table I have tags for that data set.

But I cannot seem to get the table to look right - it has an extra empty row or too much white space.

I know I can create a table using Aspose.slides for java with something like this…

ITable table = (ITable)shape;
IRow tblRow = table.getRows().get_Item(0);

List mitiSteps = risk.getMitigationSet().getMitigationStepsAsArrayList();
Iterator k = mitiSteps.iterator();

int mitiNumber = 0;
while (k.hasNext())
{

    MitigationStep mitigationStep = (MitigationStep)k.next();

    table.getRows().get_Item(mitiNumber).get_Item(0).getTextFrame().setText(mitigationStep.getTitle());
    table.getRows().get_Item(mitiNumber).get_Item(1).getTextFrame().setText(mitigationStep.getResponsiblePerson());
    table.getRows().get_Item(mitiNumber).get_Item(2).getTextFrame().setText(mitigationStep.getStartDate());
    table.getRows().get_Item(mitiNumber).get_Item(3).getTextFrame().setText(mitigationStep.getCompletedDate());
    table.getRows().get_Item(mitiNumber).get_Item(4).getTextFrame().setText(mitigationStep.getDescription());
    table.getRows().get_Item(mitiNumber).get_Item(5).getTextFrame().setText("");

    mitiNumber++;
    if (mitiSteps.size() > mitiNumber)
        // AddClone adds a row in the end of the table
        table.getRows().addClone(tblRow, false);
}

Is there a comparable way for Aspose.Word?

Hi John,

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 your target Word document showing the desired behavior. You can use Microsoft Word to create your target Word document. We will investigate as to how you are expecting your final document be generated like.
  • Please create a standalone Java application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

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

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

I don’t really have time to create a project like that. I am looking for a simple answer. Is there a way to create a table in ms word programmatically in Aspose? If so, is there some example code for this?

Hi John,

Thanks for your inquiry. Please check code examples shared in following documentation links to create table in Word documents.
Inserting a Table using DocumentBuilder
Inserting a Table Directly into the Document Object Model

Please let us know if you have any more queries.