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

Free Support Forum - aspose.com

Table Formatting in Word Document

Hi,

We’re trying to fetch data from the database and put in a table format using aspose.words for .NET. However the table requires a different level of padding/indentation for the data.

  1. We tried to do the same using a template based approach using Mail Merge.Execute, but we could not achieve the required padding/indentation (See the highlighted text in the attached doc).

  2. We could achieve the same using bookmark concept and creating the table dynamically ((See the highlighted text in the attached doc).

Is there a method to achieve the same level of formatting in the first approach?

Hi

Thanks for your request. Using a template based approach with Mail Merge you can create template with needed formatting. For example, you can use “Text to be inserted before” option of merge field to insert white space before midfield. In this case you can insert a white space as a part of merge field. Please see the following field code:

{MERGEFIELD test \b " " }

Also I do not understand, what level formatting do you mean. As I can see, there are just white spaces before text.

Hope this helps.

Best regards,

Hi All,

Just wanted to say HI to Everyone and i’m newbie here .

Hi Ann,

How can I help you? Do you have any problems with Aspose.Words?

Best regards,

Thanks for the reply. We could use white spaces but the number of spaces or tabs depends on the data. Some of the rows have multiple spaces/indentation (explaining they are grouped at different level). The level of spaces is defined by the data retrieved. So Is it possible to set this beforehand in the template?

Hi there,

Thanks for your inquiry.

In your case then, I think you can dynamically set the description column to have a custom indent by using the field merging handler.

Please see the code below, the logic you will use to calculate the level of indent will be different.

doc.MailMerge.FieldMergingCallback = new HandleParagraphIndent();

doc.MailMerge.Execute(data);

public class HandleParagraphIndent : IFieldMergingCallback

{

public void FieldMerging(FieldMergingArgs args)

{

if (args.FieldName == “Description”)

{

ParagraphFormat paraFormat = args.Field.Start.ParentParagraph.ParagraphFormat;

// Your logic for the level of indentation will most likely be different.

if (args.FieldValue.ToString().Contains("(9)"))

{

// Indent level 2

paraFormat.LeftIndent = 20;

}

else

{

// Indent level 1 by default

paraFormat.LeftIndent = 10;

}

}

}

public void ImageFieldMerging(ImageFieldMergingArgs args)

{

// Do Nothing

}

}

Thanks,