Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Mar 09, 2018 5:58 pm

Hi ,

I am new to this spire dll and i want to know how to split a word document in to multiply document by delimiter value.
Word file may contains the multiply pages as well

Desperatly need help as soon as possible. as i am running out of my release date.

masi2568
 
Posts: 6
Joined: Fri Mar 09, 2018 5:38 pm

Mon Mar 12, 2018 3:19 am

Hello,

Thanks for your post. Please refer to the below documentation to split the Word file.
https://www.e-iceblue.com/Tutorials/Spi ... -in-C.html
https://www.e-iceblue.com/Tutorials/Spi ... -in-C.html
If need further assistance, please share us with your Word file and tell us the delimiter value that you want to split by. Then we will see if it's reachable.

Best regards,
Simon
E-iceblue support team
User avatar

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

Mon Mar 12, 2018 4:29 am

Thanks . For your response.

The provided solution will not work in my case. as the file may not Contain Section.

I have attached the file path and my delimiter value for attached file is "MEYER S. BALTER, MD, FRCPC, FACP, FCCP"

I have to spit the document based on this delimiter

Kindly download the file from below path.
https://drive.google.com/file/d/1uJ5Aua ... sp=sharing

masi2568
 
Posts: 6
Joined: Fri Mar 09, 2018 5:38 pm

Mon Mar 12, 2018 10:29 am

Hello,

Thanks for your sharing.
We will investigate your requirement and reply you ASAP.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Tue Mar 13, 2018 2:33 am

Hello,

Thanks for you waiting. Please refer to the below code snippet to accomplish your task. If any query, welcome to write back.
Code: Select all
            Document original = new Document();
            original.LoadFromFile(@"Consult.docx");
            Document newWord = new Document();
            Section section = newWord.AddSection();

            int index = 0;
            foreach (Section sec in original.Sections)
            {
                foreach (DocumentObject obj in sec.Body.ChildObjects)
                {
                    if (obj is Paragraph)
                    {
                        Paragraph para = obj as Paragraph;
                        //remove page break
                        for (int i = para.ChildObjects.Count-1; i >= 0; i--)
                        {
                            if (para.ChildObjects[i] is Break)
                            {
                                para.ChildObjects.RemoveAt(i);
                            }

                        }
                        //clone content
                        section.Body.ChildObjects.Add(para.Clone());

                        if (para.Text.Contains("MEYER S. BALTER, MD, FRCPC, FACP, FCCP"))
                        {
                            newWord.SaveToFile(String.Format("result/out-{0}.docx", index), FileFormat.Docx);
                            index++;
                            newWord = new Document();
                            section = newWord.AddSection();
                        }

                    }
                    if (obj is Table)
                    {
                        section.Body.ChildObjects.Add(obj.Clone());
                    }
                }
            }


Best regards,
Simon
E-iceblue support team
User avatar

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

Tue Mar 13, 2018 6:30 am

Many Thanks! Simon

Its working as expected. You save me from killing a months on this. I really appreciate your work. Thanks!

If you help me out in one scenario that will be more grate for me. The delimiter values comes first and then the content.

Kindly take a look for the below file path
https://drive.google.com/file/d/1sRfjub ... sp=sharing

masi2568
 
Posts: 6
Joined: Fri Mar 09, 2018 5:38 pm

Tue Mar 13, 2018 7:28 am

Hello,

Glad to here that it's helpful to you. It's my pleasure. I changed the code to meet your document. Please see below.
Code: Select all
            Document original = new Document();
            original.LoadFromFile(@"Consult1.docx");
            Document newWord = new Document();
            Section section = newWord.AddSection();

            int index = 0;
            int times = 0;
            foreach (Section sec in original.Sections)
            {
                foreach (DocumentObject obj in sec.Body.ChildObjects)
                {
                    if (obj is Paragraph)
                    {
                        Paragraph para = obj as Paragraph;

                        //remove page break
                        for (int i = para.ChildObjects.Count-1; i >= 0; i--)
                        {
                            if (para.ChildObjects[i] is Break)
                            {
                                para.ChildObjects.RemoveAt(i);
                            }
                        }
                        //clone content
                        section.Body.ChildObjects.Add(para.Clone());                     
                        if (para.Text.Contains("MEYER S. BALTER, MD, FRCPC, FACP, FCCP"))
                        {
                            times++;
                            //skip saving the content before the first delimiter value
                            if (times > 1)
                            {
                                newWord.SaveToFile(String.Format("result/out-{0}.docx", index), FileFormat.Docx);
                                index++;
                                newWord = new Document();
                                section = newWord.AddSection();                           
                            }
                        }

                    }
                    if (obj is Table)
                    {
                        section.Body.ChildObjects.Add(obj.Clone());
                    }
                }
            }
            //save the last content behind last delimiter value
            newWord.SaveToFile(String.Format("result/out-{0}.docx", index), FileFormat.Docx);


Best regards,
Simon
E-icelbue support team
User avatar

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

Fri Mar 16, 2018 9:55 am

Hello,

Did you try the solution I provided? How is it going?
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

Mon Mar 19, 2018 10:58 am

Many Thanks! Simon.

Its working as expected. Thanks for your support.


Regards,
Masi

masi2568
 
Posts: 6
Joined: Fri Mar 09, 2018 5:38 pm

Tue Mar 20, 2018 1:16 am

Hello Masi,

Glad to hear that. Welcome to contact us if you need assistance. Good day.

Best regards,
Simon
E-iceblue support team
User avatar

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

Wed Mar 21, 2018 5:29 am

Hi Simon,

I have miss understood the requirement.

The current Situation is delimiter is their in the page we have to take complete content of the page up to the page end.

delimiter will be : Sean Balmain, MBChB, MRCP, MD

kindly find the file in the below path
https://drive.google.com/file/d/1OUuE3_ ... sp=sharing

masi2568
 
Posts: 6
Joined: Fri Mar 09, 2018 5:38 pm

Wed Mar 21, 2018 6:16 am

Hello Masi,

Would you please send your document to our email(support@e-iceblue.com)? I always failed to download it from your link.

Best regards,
Simon
E-iceblue support team
User avatar

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

Wed Mar 21, 2018 6:24 am

Mail Sent. Kindly check

Regards,
Masi

masi2568
 
Posts: 6
Joined: Fri Mar 09, 2018 5:38 pm

Wed Mar 21, 2018 9:05 am

Hello Masi,

Thanks for your documents. I am sorry to tell you that your requirement is not achievable this time. Because MS Word document is flow document and does not contain any information about its layout into lines and pages. We could find the paragraph with the delimiter value, but we couldn't know which page it is in. Also we can't judge which paragraph is the last one of the page.

Best regards,
Simon
E-iceblue support team
User avatar

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

Thu Jun 07, 2018 7:23 am

Hi,

I had a Word Document which had pages of multiple orientation. I used this to split the document with the delimiter, but it seems i have lost the page orientation of original document.
How do i fix this? I need to retain the original document's page orientation.

I've tried the PageSetup to change the sections orientation, but the entire document's orientation changes. Just is not meeting my condition...

deepakm
 
Posts: 1
Joined: Wed May 30, 2018 9:17 am

Return to Spire.Doc