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.

Mon Jan 23, 2017 4:43 pm

Hello!

Suppose we have a word file with an ole object inside it. It's neccessary to modify this ole object. It should stay inside the work document at the same place. How can I do it?

Probably even exist several ways how to do it.

One way may be via MemoryStream. Can I do it via DocOleObject.Container of DocOleObject.Container.Write()?
How does work DocOleObject.SetNativeData() function?

Andrey123
 
Posts: 2
Joined: Mon Jan 23, 2017 4:22 pm

Tue Jan 24, 2017 9:56 am

Hello Andrey,

Thanks for your inquiry.
There are two kinds of OLE(Linked object and Embedded object). For the Embedded object, at present our product doesn't support the feature. Our next version of Spire.Doc will add the feature. And For the Linked Object, you can see the code below as your reference.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile("OleObject.docx");
            Section sec = doc.Sections[0];
            //Traverse through all Child Objects in the body of each section
            foreach (DocumentObject obj in sec.Body.ChildObjects)
            {
                if (obj is Paragraph)
                {
                    Paragraph par = obj as Paragraph;
                    //Traverse through all Child Objects in Paragraph
                    foreach (DocumentObject o in par.ChildObjects)
                    {
                        //Find the Ole Objects and Change the link
                        if (o.DocumentObjectType == DocumentObjectType.OleObject)
                        {
                            DocOleObject Ole = o as DocOleObject;                         
                            string s = Ole.ObjectType;                                           
                            //Change the path of the link file
                            Ole.LinkPath = "sample2.xlsx";
                        }
                    }
                }
            }
            doc.SaveToFile("OleObject2.docx", Spire.Doc.FileFormat.Docx2013);
            System.Diagnostics.Process.Start("OleObject2.docx");

If there are any questions, welcome to get it back to us.

Sincerely,
Simon
E-iceblue support team
User avatar

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

Tue Jan 24, 2017 11:22 am

Hello!

Thank you for your answer! It's a pity because I need exactly the embedded variant. When are you approximately planning to release the new version?

Andrey123
 
Posts: 2
Joined: Mon Jan 23, 2017 4:22 pm

Wed Jan 25, 2017 2:29 am

Hi Andrey,

I am afraid we can't give you an ETA. And we will be on the Spring Festival vacation from Jan 27 to Feb 2. The new version will be bring into a plan after our vacation. We will inform you while the new version is released.
Any queries, please contact us.

Sincerely,
Simon
E-iceblue support team
User avatar

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

Wed Aug 16, 2017 9:51 am

Any update on this ?, is it possible to update an embedded XLS object in a Word doc with the latest version of Spire ?

tommygonk
 
Posts: 1
Joined: Thu Jul 13, 2017 12:04 pm

Wed Aug 16, 2017 10:29 am

Hello,

Thanks for your inquiry.
The feature is available now. Please refer to the follwoing code.
Code: Select all
Document doc = new Document();
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\test.docx");
            Section sec = doc.Sections[0];

           byte[] bys= File.ReadAllBytes(@"C:\Users\Administrator\Desktop\test.xlsx");
            //Traverse through all Child Objects in the body of each section
            foreach (DocumentObject obj in sec.Body.ChildObjects)
            {
                if (obj is Paragraph)
                {
                    Paragraph par = obj as Paragraph;
                    //Traverse through all Child Objects in Paragraph
                    foreach (DocumentObject o in par.ChildObjects)
                    {
                        //Find the Ole Objects and Change the link
                        if (o.DocumentObjectType == DocumentObjectType.OleObject)
                        {
                            DocOleObject Ole = o as DocOleObject;
                            // Since we can not automatically scan the document, set the image icon by yourself
                            DocPicture pic=new DocPicture(doc);
                            pic.LoadImage(Image.FromFile(@"C:\Users\Administrator\Pictures\pic.jpg"));
                            Ole.SetOlePicture(pic);
                            Ole.SetNativeData(bys);
                        }
                    }
                }
            }
            doc.SaveToFile("OleObject2.docx", Spire.Doc.FileFormat.Docx2013);


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Aug 22, 2017 8:36 am

Hello tommygonk,

How is your issue now? Did the solution I provided work?
Your feedback information will be greatly appreciated.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.Doc