Article ID: 257757 - View products that this article applies to.
This article was previously published under Q257757
Developers can use Automation in Microsoft Office to build custom solutions that use the capabilities and the features that are built into the Office product. Although such programmatic development can be implemented on a client system with relative ease, a number of complications can occur if Automation takes place from server-side code such as Microsoft Active Server Pages (ASP), ASP.NET, DCOM, or a Windows NT service.
This article discusses the complications that developers may face. The article also offers alternatives to Automation that can speed performance. Developers should be aware, however, that the suggestions that this article provides are for informational purposes only. Microsoft does not recommend or support server-side Automation of Office.
Note In this context, the Microsoft 2007 Office System Driver and the 2010 Access Database Engine are considered Microsoft Office components. The term "server-side" also applies to code that is running on a Windows workstation, if the code is running from a Windows workstation other than the interactive station of the user who is logged on. For example, code that is started by Task Scheduler under the SYSTEM account runs in the same environment as "server-side" ASP code or as DCOM code. Therefore, many of the issues that this article describes may occur. For more information about Windows workstations and about COM, see the "More Information" section and the "References" section.
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.
Problems using server-side Automation of OfficeDevelopers who try to use Office in a server-side solution need to be aware of five major areas in which Office behaves differently than anticipated because of the environment. If your code is to run successfully, you must address these issues and minimize their effects as much as possible. Consider these issues carefully when you build your application. One solution cannot address all the issues. Different designs require you to prioritize the elements differently.
In addition to these issues, one of the following common errors may occur when you try to automate Office server-side:
Alternatives to server-side AutomationMicrosoft 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.
The Open XML file formats are a public standard. To obtain a copy of the specification, visit the following Web site:
http://www.ecma-international.org/publications/standards/Ecma-376.htmMicrosoft provides an SDK for manipulating Open XML file formats from the .NET 3.x Framework. For more information about the SDK and about how to use the SDK to create or edit Open XML files, visit the following Microsoft Developer Network (MSDN) Web sites:
Open XML SDK Documentation
How to: Manipulate Office Open XML Formats Documents
Manipulating Word 2007 Files with the Open XML Object Model (Part 1 of 3)
Manipulating Word 2007 Files with the Open XML Object Model (Part 2 of 3)
Manipulating Word 2007 Files with the Open XML Object Model (Part 3 of 3)
Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Object Model (Part 1 of 2)
Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Object Model (Part 2 of 2)
Building Server-Side Document Generation Solutions Using the Open XML Object Model (Part 1 of 2)
Building Server-Side Document Generation Solutions Using the Open XML Object Model (Part 2 of 2)For more information about using Open XML from the .NET 3.0 Framework and for an example, click the following article numbers to view the articles in the Microsoft Knowledge Base:
(https://support.microsoft.com/kb/932921/ )How to use components of the .NET Framework 3.0 to create and then to stream an Office Word 2007 document and an Office Excel 2007 workbook to a client computer
931866Users who are running earlier versions of Office (such as Office 2000, Office XP, and Office 2003) can view and edit Open XML files if the users install the free compatibility pack download from the Microsoft Web site. To download and install the compatibility pack, visit the following Microsoft Web site:
(https://support.microsoft.com/kb/931866/ )How to use the Office XML file format and the packaging components from the .NET Framework 3.0 to create a simple Excel 2007 workbook or a simple Word 2007 document
Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 file formatsWhen you stream Open XML files from ASP or from ASP.NET, you must provide the correct Multipurpose Internet Mail Extension (MIME) type for the content that you stream. For a listing of the MIME types for Office 2007 files, visit the following Web site:
http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/05/08/office-2007-open-xml-mime-types.aspxIf you are targeting pre-Office 2007 clients only, and you do not want to require the use of Open XML in the solution, you can use other non-binary Office file formats, such as HTML, XML, and RTF. You can then stream these files to a client by using a MIME type so that the resulting text appears in Office. The document can be edited, saved, and even returned to the server by using ASP on the server.
For more information about any of these topics, and for examples that show how to implement them, click the following article numbers to view the articles in the Microsoft Knowledge Base:
(https://support.microsoft.com/kb/270906/ )How to use ASP to generate a Rich Text Format (RTF) document to stream to Microsoft Word
(https://support.microsoft.com/kb/198703/ )How to automate Excel from a client-side VBScript
(https://support.microsoft.com/kb/199841/ )How to display ASP results using Excel in IE with MIME types
(https://support.microsoft.com/kb/260239/ )How to format cell data when you are creating an Excel file with an Active Server Pages page
(https://support.microsoft.com/kb/278973/ )ExcelADO demonstrates how to use ADO to read and write data in Excel workbooks
(https://support.microsoft.com/kb/286023/ )How to use a VB ActiveX component for Word automation from Internet Explorer
288130If your business requires the server-side creation of the Office 97, Office 2000, Office XP, and Office 2003 binary file formats, third-party vendors offer components that can help you. Microsoft does not provide any such components, so you will need to either build a solution yourself or purchase one from a third-party vendor. Many different third-party products are available. You should investigate each solution to best match the vendor to your business needs.If you want to build your own solution that edits the Office 97, Office 2000, Office XP, and Office 2003 binary file formats directly, you can obtain the file format specifications for free under the terms of the Microsoft Open Specification Promise (OSP). No technical support is available for the documentation or for the products that you create, but documentation is available. For more information, visit the following Web site:
(https://support.microsoft.com/kb/288130/ )How to use ASP to build spreadsheet XML for client-side display
http://www.microsoft.com/interop/docs/officebinaryformats.mspxServer-side solutions also may want to allow users to upload files, and then have the server render the files for viewing on the Web or on other mediums. Microsoft is currently working to offer such features, and provides an early version of this capability in Microsoft Excel Services.
Excel Services is a new server technology that is included in Microsoft Office SharePoint Server 2007 and that enables you to load, calculate, and display Excel workbooks on Office SharePoint Server 2007. For more information about Excel Services, visit the following Microsoft Developer Network (MSDN) Web sites:
Excel Services Overview
Walkthrough: Developing a Custom Application Using Excel Web Services
Creating Business Applications by Using Excel Services and Office Open XML FormatsWord Automation Services is a new service application in SharePoint Server 2010. Word Automation Services provides unattended, server-side conversion of documents into formats that are supported by the Microsoft Word client application.
Word Automation Services Overview
Introducing Word Automation ServicesYou need to evaluate which of the options that this article describes suits your needs, and how best to deploy your solution. The information that this article provides is not guaranteed to resolve all issues for all clients. You are encouraged to test your solution thoroughly before you deploy the solution.
Article ID: 257757 - Last Review: July 12, 2013 - Revision: 19.3