We are using spire doc to convert to Text file. We want to remove all strike through text when we are converting.
Please provide help.
Document doc = new Document();
doc.LoadFromFile(fileName, Spire.Doc.FileFormat.Docx2010);
foreach (Section s in doc.Sections)
{
foreach(Paragraph p in s.Paragraphs)
{
var childs=p.ChildObjects;
int count = childs.Count;
for (int i = 0; i < count;i++ )
{
if (childs[i] is TextRange)
{
var tr = childs[i] as TextRange;
//remove text with strike through
if (tr.CharacterFormat.IsStrikeout)
{
childs.Remove(childs[i]);
count--;
}
}
}
}
}
doc.SaveToFile("result.txt", Spire.Doc.FileFormat.Txt);
Document doc = new Document();
doc.LoadFromFile(fileName, Spire.Doc.FileFormat.Docx2010);
foreach (Section s in doc.Sections)
{
foreach (Paragraph p in s.Paragraphs)
{
//remove numbered list with strike through
if (p.ListText!="" && p.ListFormat.CurrentListLevel.CharacterFormat.IsStrikeout)
{
p.ListFormat.ClearFormatting();
}
//remove text with strike through
var childs = p.ChildObjects;
int count = childs.Count;
for (int i = count - 1; i >= 0; i--)
{
if (childs[i] is TextRange)
{
var tr = childs[i] as TextRange;
if (tr.CharacterFormat.IsStrikeout)
{
childs.Remove(childs[i]);
}
}
}
}
}
doc.SaveToFile("result.txt", Spire.Doc.FileFormat.Txt);