Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Mon Nov 06, 2017 10:37 am

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.

yogeshmsharma
 
Posts: 17
Joined: Mon Sep 25, 2017 5:25 pm

Tue Nov 07, 2017 3:05 am

Hello,

Thanks for your inquiry. Please refer to the below code snippet to remove the text with strike through.
Code: Select all
            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);


Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Wed Nov 08, 2017 10:06 am

Thanks for your answer, Will try this

yogeshmsharma
 
Posts: 17
Joined: Mon Sep 25, 2017 5:25 pm

Mon Nov 13, 2017 9:09 am

Hello,

Greetings from E-iceblue!
Has your issue been resolved?
Your feedback will be greatly appreciated.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Wed Nov 22, 2017 9:08 am

for all strike through text its not working.if text is bold or italic or in other font , its not removing.

ParasXOR
 
Posts: 28
Joined: Wed Nov 22, 2017 6:13 am

Wed Nov 22, 2017 9:35 am

Hello,

Thanks for your post. After an initial test with Spire.Doc Pack(hot fix) Version:6.0.52, I was unable to reproduced the issue on my side. To help us investigate further, would you please share us with the word document that can't remove the strike through text?

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Fri Nov 24, 2017 5:46 am

Please check attached file for more details.
You do not have the required permissions to view the files attached to this post.

ParasXOR
 
Posts: 28
Joined: Wed Nov 22, 2017 6:13 am

Fri Nov 24, 2017 8:55 am

Hello,

Thanks for your sharing. I have made some improvements to the demo. Please refer to the below code snippet and try again.
Code: Select all
            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);


Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Mon Nov 27, 2017 9:49 am

Hello,

Greeting from E-iceblue.
Did you try the solution I provided? Is it helpful?
We will appreciate it if you could give us some feedback.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Mon Nov 27, 2017 9:55 am

Thanks for sharing solution.
Facing one minor issue with this,number of list not getting remove.
if spacing also gets remove it will be helpful.

See below example:
Example:

II - condições
III - (Revogado pela Resolução nº 2.303, de 25/7/1996.)

IV

IV - obrigatoriedade de comunica

V

V - inclusão do nome do depositante no Cadastro de

VI

VI - informação de que os cheques liquidados, uma vez microfil

Added file for the same after conversion roman numbers are getting repeated and highlighted text has not removed.
Thanks in advance.
You do not have the required permissions to view the files attached to this post.
Last edited by ParasXOR on Tue Nov 28, 2017 6:50 am, edited 1 time in total.

ParasXOR
 
Posts: 28
Joined: Wed Nov 22, 2017 6:13 am

Tue Nov 28, 2017 6:10 am

Hello,

Thanks for your feedback. I have added the code to remove strike through text in table. Please refer to the attached demo and result file.

Best regards,
Simon
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Wed Nov 29, 2017 3:23 am

Hello,

Greeting from E-iceblue.
Has the solution resolved your issue?
Please give us some feedback at your convenience.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Wed Nov 29, 2017 6:32 am

Thanks for solution.
it is help full in removing roman number and space.
file has been attached.
Highlighted strike through not removing.
Some content getting loss for this file.
You do not have the required permissions to view the files attached to this post.

ParasXOR
 
Posts: 28
Joined: Wed Nov 22, 2017 6:13 am

Wed Nov 29, 2017 9:53 am

Hello,

Thanks for your sharing.
I find that the formats of two highlight paragraphs are not strike through, there is a line shape in them. Hence they can't be removed with the demo I provided. At present, we don't have a proper solution to this case. I am sorry for the inconvenience.
On the other hand, there is no content lost in the result file on my side.
Please refer to the attached code and and result document.

Best regards,
Simon
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Thu Jun 11, 2020 5:27 pm

Thank you so much for this amazing thread. I am facing this problem in the last few weeks. Finally, I have got my answer. Well, I used to say cross out text instead of strikethrough the text. :D Anyway, I just want to say, Thank you very much.

chriswatson
 
Posts: 1
Joined: Thu Jun 11, 2020 5:07 pm

Return to Spire.Doc