aviv
aviv

Reputation: 2809

Working with Microsoft Office Word on the Back-end

Currently I have an application that modifies Microsoft Office Word documents at the back-end side — adding a cover page and replacing some text. In order to do so, we use COM (Component Object Model) to manipulate the .docx / .doc files. We process more than 1000 documents a day.

The problem is that it is very slow and "hangs" occasionally, and basically is not recommended to be used in that way.

Is there a library / component to be used to manipulate and edit Microsoft Office Word on the server side? Most preferable with golang or php and if it can run on Linux it is even better, but also Windows only lib can help.

Upvotes: 0

Views: 1424

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49443

The Considerations for server-side Automation of Office article states the following:

All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended.

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.

Alternatives

  1. The Open XML SDK, see Welcome to the Open XML SDK 2.5 for Office for more information.

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 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 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.

  1. If you want to deal with old document formats you may use any third-party components designed for the server-side execution, for example, Aspose.

Upvotes: 2

Related Questions