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

Free Support Forum - aspose.com

Problem with left align for clone table

Hi

I have the following code to clone table from first page to second column

Document doc = new Document(@"C:\Documents and Settings\Desktop\TestTable.docx");

Aspose.Words.Tables.Table myTable = doc.FirstSection.Body.Tables[0];

Aspose.Words.Tables.Table myTable1 = doc.FirstSection.Body.Tables[1];

Aspose.Words.Tables.Table tableClone1 = (Aspose.Words.Tables.Table)myTable.Clone(true);

Aspose.Words.Tables.Table tableClone2 = (Aspose.Words.Tables.Table)myTable1.Clone(true);

Section section = new Section(doc);

doc.AppendChild(section);

section.PageSetup.SectionStart = SectionStart.NewPage;

section.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;

section.PageSetup.LeftMargin = doc.FirstSection.PageSetup.LeftMargin;

section.PageSetup.RightMargin = doc.FirstSection.PageSetup.RightMargin;

section.PageSetup.TopMargin = doc.FirstSection.PageSetup.TopMargin;

section.PageSetup.BottomMargin = doc.FirstSection.PageSetup.BottomMargin;

Body body = new Body(doc);

section.AppendChild(body);

body.AppendChild(tableClone1);

body.AppendChild(tableClone2);

doc.Save(@"C:\Documents and Settings\Desktop\TestTableOut.docx");

My issue is like my left align is not working for the second page

Am attaching my Template and out put also

In my out put the table in the second page don't have same left align of the first page table how to make same left align in both page

Regards

Ajeesh M J

Hi Ajeesh,


Thanks for your inquiry. Please see the following changes in your code:

Document doc = new
Document(@“C:\Temp\TestTable.docx”);

Aspose.Words.Tables.Table myTable = doc.FirstSection.Body.Tables[0];

Aspose.Words.Tables.Table myTable1 = doc.FirstSection.Body.Tables[1];

Aspose.Words.Tables.Table tableClone1 = (Aspose.Words.Tables.Table)myTable.Clone(true);

Aspose.Words.Tables.Table tableClone2 = (Aspose.Words.Tables.Table)myTable1.Clone(true);

//Section section = new Section(doc);

Section section = (Section)doc.FirstSection.Clone(false);

doc.AppendChild(section);

//section.PageSetup.SectionStart = SectionStart.NewPage;

//section.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;

//section.PageSetup.LeftMargin = doc.FirstSection.PageSetup.LeftMargin;

//section.PageSetup.RightMargin = doc.FirstSection.PageSetup.RightMargin;

//section.PageSetup.TopMargin = doc.FirstSection.PageSetup.TopMargin;

//section.PageSetup.BottomMargin = doc.FirstSection.PageSetup.BottomMargin;

Body body = new Body(doc);

section.AppendChild(body);

body.AppendChild(tableClone1);

body.AppendChild(tableClone2);

doc.Save(@"C:\Temp\out.docx");


I hope, this helps.

Best regards,

Hi

Thanks for your reply.Your code is working partially.IAfter implementing your code,in my second page am getting the two tables get merged that is am not getting as a separate tables.Am attaching the input doc and out put doc please have a lot..

Regards

Ajeesh M J

Hi Ajeesh,


Thanks for your inquiry. In your case, Aspose.Words does generate two Tables in second Section of the output document; however, if you re-save the final document to DOCX format using Microsoft Word, it merges those two consecutive Tables into one. To prevent Microsoft Word from doing this you could have inserted an empty Paragraph in between those Tables as follows:

Document doc = new
Document(@“C:\Temp\TestTable.docx”);

Aspose.Words.Tables.Table myTable = doc.FirstSection.Body.Tables[0];

Aspose.Words.Tables.Table myTable1 = doc.FirstSection.Body.Tables[1];

Aspose.Words.Tables.Table tableClone1 = (Aspose.Words.Tables.Table)myTable.Clone(true);

Aspose.Words.Tables.Table tableClone2 = (Aspose.Words.Tables.Table)myTable1.Clone(true);

Section section = (Section)doc.FirstSection.Clone(false);

doc.AppendChild(section);

Body body = new Body(doc);

section.AppendChild(body);

body.AppendChild(tableClone1);

Paragraph emptyPara = new Paragraph(doc);

emptyPara.ParagraphFormat.SpaceAfter = 0;

emptyPara.ParagraphFormat.SpaceBefore = 0;

emptyPara.ParagraphBreakFont.Size = 1;

body.AppendChild(emptyPara);

body.AppendChild(tableClone2);

doc.Save(@“C:\Temp\output.docx”);


I hope, this helps.

Best regards,