Hello ,
To remove line items from a Word report programmatically, you can use the Microsoft Office Open XML SDK.
sample code snippet in C# that demonstrates how to remove line items from a Word document:
write this code :
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
public void RemoveLineItems(string filePath)
{
using (WordprocessingDocument document = WordprocessingDocument.Open(filePath, true))
{
// Get the main document part
MainDocumentPart mainPart = document.MainDocumentPart;
// Get all paragraphs in the document
var paragraphs = mainPart.Document.Body.Descendants<Paragraph>();
foreach (var paragraph in paragraphs)
{
// Check if the paragraph contains line item content
if (paragraph.InnerText.Contains("Line Item"))
{
// Remove the paragraph
paragraph.Remove();
}
}
// Save the changes
mainPart.Document.Save();
}
}
if any issue to contant me , i will help you