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

Free Support Forum - aspose.com

Inserting table from other document into paragraph is failing

Hi,


I need to copy a chart followed by a table into a document based on bookmark.

Coping chart from Memory Stream into bookmark area is working fine but when I try to insert table from another document below the chart, it fails with exception " Cannot insert a node of this type at this location".

Code:

//Document that has tables
Document wordDocWithTables = new Document(destinationDir + Consts.DataAvailabilityByProtocolWordFile);

//Reading the charts
NodeCollection tables = wordDocWithTables.GetChildNodes(NodeType.Table, true);

//Document builder from destination doc
DocumentBuilder builder = new DocumentBuilder(doc);
int height = Consts.ImageHeight;
int width = Consts.ImageWidth;
int seperator = Consts.SeperatorHeight;

int tableCount = 0;
foreach (MemoryStream image in chartimages)
{
builder.MoveToBookmark(Consts.BookMarkDataAvailabilityByProtocolSection);
builder.CurrentParagraph.ParagraphFormat.ClearFormatting();
builder.CurrentParagraph.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
Paragraph paragraphForChart = builder.InsertParagraph();

Shape shape = new Shape(doc, ShapeType.Image);
shape.ImageData.SetImage(image);
shape.Height = height;
shape.Width = width;
shape.WrapType = WrapType.Inline;
shape.WrapSide = WrapSide.Both;
shape.Left = 0;

//Appending the charts to the paragraph
paragraphForChart.AppendChild(shape);

if (tables.Count > 0)
{
//Creating new paragraph
Paragraph paragraphForTable = builder.InsertParagraph();

Node tableNode = doc.ImportNode(tables[tableCount], true, ImportFormatMode.KeepSourceFormatting);

//Insert table into the destination document
paragraphForChart.AppendChild(tableNode);
}

}

Please provide any suggestion to make it work. Thank You.

Regards,
Aniket

Hi,


Do you have any updates on the issue, Its kind of urgent. Thanking in anticipation.

Regards,
Aniket

Hi Aniket,


Thanks for your inquiry and sorry for the delayed response. Could you please attach your Word documents here for testing? I will investigate the issue on my side and provide you more information. Please also create your target document by using Microsoft Word for our reference that displays the final position of Table in the output document. I will provide you code to achieve the same by using Aspose.Words.

Best regards,

Hi,

Thanks for the reply. I tried few thinks and looks like my issue has been fixed.

I tried following code, and i am able to add the table below chart.

builder.CurrentParagraph.ParentNode.InsertAfter(tableNode, builder.CurrentParagraph);

Regards,
Aniket

Hi Aniket,


Thanks for your inquiry. It’s great you were able to find what you were looking for. In case you have further inquires or need any help, please let us know.

Best regards,