I tried below code i am getting paragraph , images ,bullets. I want only paragraph could you please help me for that.
Document dstDoc = new Document("C:\\Users\\Yuvaraj\\Output word document.docx");
Document srcDoc = new Document("C:\\Users\\Yuvaraj\\Input word document.docx");
NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KeepSourceFormatting);
foreach (Paragraph node in srcDoc.GetChildNodes(NodeType.Paragraph, true))
{
if (node.ParentNode.NodeType != NodeType.Cell)
{
Node importNode = importer.ImportNode(node, true);
dstDoc.FirstSection.Body.AppendChild(importNode);
}
}
dstDoc.Save("C:\\Users\\Yuvaraj\\Paragraph1.docx");
@Yuvarajshivananjappa Shapes are inline nodes so they are child nodes of paragraphs. Bullets are part of paragraph format. Please see our documentation to learn more about Aspose.Words Document Object Model. To get the desired output, you should remove shapes and numbering from the imported paragraphs:
NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KeepSourceFormatting);
foreach (Paragraph node in srcDoc.GetChildNodes(NodeType.Paragraph, true))
{
if (node.ParentNode.NodeType != NodeType.Cell)
{
Paragraph importNode = (Paragraph)importer.ImportNode(node, true);
// remove numbering.
if (importNode.IsListItem)
importNode.ListFormat.RemoveNumbers();
// Remove shapes.
importNode.GetChildNodes(NodeType.Shape, true).Clear();
dstDoc.FirstSection.Body.AppendChild(importNode);
}
}
@alexey.noskov I am not getting an expected output…from the given code I need only all paragraph content and paragraph headings from the given document **except bulletins content and headings **
but your given code just removed the ListFormat.RemoveNumbers() from bulletins.
@Yuvarajshivananjappa Could you please attach your input, output and expected output documents here? We will check the issue and provide you more information.
@Yuvarajshivananjappa Looks like you need to skip list items. If so, you can simply modify the condition like this:
if (!node.IsListItem && (node.ParentNode.NodeType != NodeType.Cell))
{
// Process paragraph which are not in the table and are not list items.
// .......
}