In one of our projects am storing the msword document in DB, modifying the word document programatically and generating pdf, which is working fine.
One of the usecase In the word document is, if user links an excel sheet with paste special link option.
This link works i.e data change in the excel reflects in the word document till the both the files in the end users local machine.
This does not work when the word document is saved to DB as blob and generating the pdf from that blob.
Reason identified is linked excel sheet in the word is not in the same path. So i was trying to figure out the link using aspose word api and trying to manipulate.
Any help on this is highly appreciated
The Considerations for server-side Automation of Office states the following:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
You may consider using the Open XML SDK or any third-party components designed for the server-side execution (like you chose).
Related
I am using Visual Studio and developing an Office add-in. I need to identify same shapes and pictures and replace them.
I try to use OpenXml to do that but it doesn't seem to be able to be modified in files in use. It doesn't seem to work as an office add-in because it doesn't work with files that are already open.
And I have searched for many hours on the internet but not found a way to do that.
Help me please.
Thank you
TL; DR: OpenXML and Office add-ins (including VSTO) are competing technologies for different use cases that may lead to runtime issues if combined. Best to stick to just one.
I am ... developing a office add-in. I need to identify same shapes and pictures and replace them. I try to use OpenXml to do that but it doesn't seem to be able to be modified in files in use.
OpenXML is an API for creating/reading/modifying Office documents (Office 2010+ to be exact) that adhere to the contemporary XML document format such as Word 2010. It does so by manipulating the document directly at the file level rather than using COM. In fact it does not require Word to be installed on the machine at all! This makes OpenXML a rather light-weight approach to interacting with Office documents.
Unfortunately OpenXML (or other file-based approaches) are unsuitable for Office add-ins (VSTO or otherwise) if both are targeting the same document. This is because the document is already loaded into say Word and Word is hosting your add-in. Any attempt to modify the underlying file (including OpenXML by anything but Word or Word APIs) that represents the loaded document will encounter a:
sharing violation
To put this another way:
In order to run your Office add-in the Office app needs to be running first. This is known as hosting
Operations on Office documents orchestrated by your add-in require the document to be loaded into the Office app first
No external Windows process or in-process (add-in) operation can directly change the underlying Office document file whilst it is open in the Office app. (Add-ins can indirectly save to the file using Office APIs and ask the Office app to Save though generally such APIs don't expose any raw file interfaces to the caller so the later is probably not the same thing)
What to do?
My recommendation is to either:
a) use a pure OpenXML approach and discard the Office add-in or...
b) use a pure Office add-in (VSTO) approach and discard the OpenXML code
Considering that it seems you already have code for shapes and pictures via the OpenXML approach, perhaps option a) is the best.
See also
Open XML SDK
Visual Studio Tools for Office (VSTO)
I need to replace user's meta tags #likethis# inside a docx file for a value in database. It was fine replacing simple strings editing the byte array of file directly. But it became more complex when I needed to load a table of data. So I had to try to use this lib but its documentation it's pretty poor.
I find on this reference how to replace bookmarks by values
https://social.msdn.microsoft.com/Forums/Lync/en-US/ed7278b1-1fc7-44d5-9e87-4c3e41a110cf/how-to-modify-bookmarked-fields-in-word-docx-file-from-code?forum=worddev
But there's a way to track down a string inside the text and replace it for any content (like other text, or a table or a image like a logo) ?
The Considerations for server-side Automation of Office article states the following:
Microsoft strongly recommends that developers find alternatives to Automation of Office if they need to develop server-side solutions. Because of the limitations to Office's design, changes to Office configuration are not enough to resolve all issues. Microsoft strongly recommends a number of alternatives that do not require Office to be installed server-side, and that can perform most common tasks more efficiently and more quickly than Automation. Before you involve Office as a server-side component in your project, consider alternatives.
Most server-side Automation tasks involve document creation or editing. Office 2007 supports new Open XML file formats that let developers create, edit, read, and transform file content on the server side. These file formats use the System.IO.Package.IO namespace in the Microsoft .NET 3.x Framework to edit Office files without using the Office client applications themselves. This is the recommended and supported method for handling changes to Office files from a service.
As a workaround you may consider using the Open XML SDK for open XML documents. Or just any third-party wrappers designed for the server-side execution (for example, Aspose).
My requirement is to load a PPTX file directly from AWS s3 storage.
I'm using INTEROP to manipulate with Powerpoint files. So instead of downloading file from S3 to a specified location on server can I directly load the file from S3.
Here is my current code for loading PPTX file.
var pptPresentation = pptApplication.Presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
Any suggestion would be helpful.
Thanks
You have to download the file locally.
Note, the Considerations for server-side Automation of Office article states the following:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
You may consider using the Open XML SDK for manipulating open xml files. See Presentations (Open XML SDK) for a sample code.
I've read its not really recommended to use interop office to modify documents server side. The problem is the libraries for this kind of thing are really expensive.
Requirements and implementation in my case:
The modified documents must be from office 2003+.
Code will run on windows server.
Documents will be copied using external code then my class will take that copied document (file path), modify it, save it.
There should be no problem with read-only because there will be one document per user.
What kind of problems can be expected?
Can it be a problem if 50 different users use my class at the same time to modify different documents?
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
You can read more about that in the Considerations for server-side Automation of Office article.
As a workaround you can use:
Open XML SDK for manipulating files that are in open XML format.
Third-party commercial components.
Use NPOI to modify .xls documents.
Unfortunately I don't know libraries that work with .doc format.
I would like to know whether its possible to open Open word 2003 (doc) file using open xml file format API? like office 2007.
I have one windows service through which I am trying to open and edit doc files but getting lot of problems.I have posted question regarding that problem here but got no answer.
After lot of googling, I came across this page which tells about microsoft recommendations of Office automation on server-side code. Microsoft suggests that office automation should not be implemented in server-side code,as office applications are made for interactive client workstations. This page does not tell if its possible and how to open doc files using open xml format API.
Basically, I want one windows service which will take doc file as an input, open it, edit it and save it. How to achieve this?
My development enviornment : C#, .net 2.0 framework, Windows Vista, Office 2003
I think you might be missing the point of Office interop. Using Office interop basically means you communicate with a running Microsoft Office Word/Excel process and manipulate a document/spreadsheet in a defined manner. There is no need to directly modify a word document itself if you use Office interop.
If you wish to modify an Office .doc document directly without the presence of Microsoft Office, then your best bet would be to Google for a library that will directly manipulate .doc for you, although these libraries tend to be fairly buggy, and where they aren't buggy, they're expensive.
EDIT: If you're asking whether or not you can use Office 2007 interop to manipulate a .doc file, then the answer is yes.
You can't. Microsoft introduced office open xml standard from Word 2007. Word 2003 uses binary format.