Creating and inserting rows and columns using builder

hi ,
could you please tell me how to create and insert rows and columns with documentbuilder class.
and iam attatching attachment. can any one give solution for that. and i am new for aspose. that should be like attatchment. i have done using mergefield but what i want is when i dont get any data from database. i should not display respective column in the template. but now using mergefield it getting displayed.

Hi

Thanks for your inquiry. Please see the following link to learn how to build table using DocumentBuilder.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/inserting-a-table.html

Also I think the following link could be useful for you (if you need to hide some rows in your table during mail merge)

Hope this helps.

Best regards.

hi alaxey,

i am not getting e.field.start property in the mergefield event handler

i have written code as
// calling
doc.MailMerge.MergeField += new MergeFieldEventHandler(mailmergeEvent);

// called
void mailmergeEvent(object sender, MergeFieldEventArgs e)
{
if (string.IsNullOrEmpty(e.FieldValue.ToString()))
{
Aspose.Words.Node parentRow = e.Field.Start.GetAncestor(typeof(Aspose.Words.Row));
parentRow.Remove();
}
}

Hi Ravi,

What do you mean? This code works fine on my side. Also from your code I see that you are using old version of Aspose.Words. Please try using the latest version. You can download it from here.

http://www.aspose.com/community/files/51/file-format-components/aspose.words/entry127076.aspx

Here is code I used for testing

public void Test264()

{

DataTable table = new DataTable(“test”);

table.Columns.Add(“Col1”);

table.Columns.Add(“Col2”);

table.Columns.Add(“Col3”);

table.Rows.Add(new object[] { “test”, “”, “Test” });

table.Rows.Add(new object[] { “”, “xfgdf”, “Test” });

table.Rows.Add(new object[] { “”, “”, “Test” });

Document doc = new Document(@“Test264\in.doc”);

doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField264);

doc.MailMerge.ExecuteWithRegions(table);

doc.Save(@“Test264\out.doc”);

}

void MailMerge_MergeField264(object sender, MergeFieldEventArgs e)

{

if (string.IsNullOrEmpty(e.FieldValue.ToString()))

{

Aspose.Words.Node parentRow = e.Field.Start.GetAncestor(NodeType.Row);

parentRow.Remove();

}

}

Best regards.

hi alaxey,

Right Now our Company is using license key for 3.6.1.0. your link is downloaded 5.2.0.0 version. Is our key used for this new version.

Hi

Thanks for your request. Every Aspose license carries a one-year subscription for free upgrades to any new versions or fixes that come out during this time.

So you can’t upgrade to the latest version.

Please check expiration date of your license (open license file using NotePad.) you should see the following tags there

20090521

This means that expiration date of your license is 21.05.2009. And you can free upgrade to version published before this date.

Best regards.

hi alexey,
thanks for response. and my company license is as like

20081211

could i add new DLL to my solution with our Evalution Version message. if not how could i solve my problem to remove parent row with old version. Is there any other way.

Hi

Thank you for additional information. With this license you can free upgrade to the latest version.

You can use Aspose.Words in evaluation mode absolutely free anyway.

Best regards.

hi alexey,

thank you for good guidence. i have added new dll. now i am getting right result. Thank you once again…
and now i want to delete pages from template how to do it .

Hi

Thanks for your inquiry. I already answered this question here <A href="https://forum.aspose.com/t/105929

Best regards.

hi alexey,
yester problem was not solved. when i get dbnull.value from database then i am getting exception while parentrow.remove() method…

hi alexey,
yester day problem was not solved. when i get dbnull.value from database then i am getting exception while parentrow.remove() method…

when i add the new DLL many problems like Cell, cellformat like are not supporting coukd you please give me solution …

hi alexey,
yester day problem was not solved. when i get dbnull.value from database then i am getting exception while parentrow.remove() method…

when i add the new DLL many problems like Cell, cellformat like are not supporting coukd you please give me solution …

i am sending my code

Aspose.Words.Cell cell = builder.InsertCell();
cell.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(159, 171, 210);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
cell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
cell.CellFormat.Width =100;

Hi

Thanks for your request.

  1. What error are you getting? Please attach your template for testing.

  2. There are some differences in API in the new version.

The breaking changes in Aspose.Words for .NET 5.x.x are:

  1. All collection classes, such as Paragraphs, Runs, Tables, Bookmarks etc have been renamed into ParagraphCollection, RunCollection, TableCollection, BookmarkCollection, CellCollection accordingly.

  2. New namespaces Aspose.Words.Fields, Aspose.Words.Lists, Aspose.Words.Markup, Aspose.Words.Properties and Aspose.Words.Tables were introduced and classes moved into the new namespaces.

So you should just add “using Aspose.Words.Tables;”.

Best regards.

hi,

i am attaching my template and the error i am getting is

***An exception of type ‘System.NullReferenceException’ occurred in App_Web_h1yc4xsy.dll but was not handled in user code

Additional information: Object reference not set to an instance of an object.***

Hi

Thank you for additional information. I can’t reproduce this issue on my side. Also I changed you template a little (regarding page removing). Please try it out.

Also you can try to check if parentRow is null

void MailMerge_MergeField264(object sender, MergeFieldEventArgs e)

{

if (string.IsNullOrEmpty(e.FieldValue.ToString()))

{

Aspose.Words.Node parentRow = e.Field.Start.GetAncestor(NodeType.Row);

if (parentRow!=null)

parentRow.Remove();

}

}

Best regards.

hi ,

the code works fine when there is only one event. and when i have more like mergeFieldEventHandler and MergeImageEventHandler events and when i execute doc.mailmerge.executewithregions then i am getting system.notsupportedException and seek operation.

here cont i use two events at a time.

using MergeImageFieldEventHandler i am just reducing the image height in the template.

using MergeFieldEventHandler i am removing empty fields(parent rows) in the template.

doc.MailMerge.MergeImageField += new MergeImageFieldEventHandler(ImageMerge);

doc.MailMerge.MergeField += new MergeFieldEventHandler(mailmergeEvetns);

doc.MailMerge.ExecuteWithRegions(table);(system.notsupportedException)

Hi

This question is already answered in <A href="https://forum.aspose.com/t/105891

Best regards.