问题
Possible Duplicate:
Creating, opening and printing a word file from C++
Hi,
I need to create a word document from a c++ program, Im using windows 2008 server,office automation fails sometimes here and also I need non interactive service to handle as automation provides interactive service.I've implemented automation it fails sometimes
What are the ways I can create openoffice / word doc?
can you please suggest me any links or tutorials to do the above.
PS - I came to know about couple of methods 1.Openoffice SDK 2.OpenXML SDK
If you have worked with the above please suggest me which of the above to use.
Thanks in advance
回答1:
Here's a newly released C library called libOPC which has the same intent as the Open XML SDK, but can be used in all of Linux/Windows/Mac/etc. You can read about it here: libOPC version 0.0.1 released and get the code from CodePlex (be sure to check the documentation page for demo videos).
回答2:
I advise you to look at this page where the author explains what solution he took to generate Word documents on a server, without MsWord being available, without automation or thirdparty libraries.
回答3:
Using the Open Office XML SDK and Open Office XML directly are good options if you're targeting Word 2007 and up.
If you're targeting users of Word 2003 and earlier then it may not be the best option. However, even those users can install a free filter to be able to open Word 2007 (.docx) documents within Word 2003. You can link to this download from your application. Most people with Word 2003 or earlier probably have this filter installed anyways since they will often run into situations where people share newer files.
http://www.microsoft.com/DOWNLOADS/en/details.aspx?familyid=941b3470-3ae9-4aee-8f43-c6bb74cd1466&displaylang=en
Open Office XML SDK is a .NET API for reading and writing .docx and other Office 2007 files. If you're using C++/CLI then you can use this easily enough and it will simplify the process of writing .docx files.
http://www.microsoft.com/downloads/en/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en
However, if you're using straight C++ with no .NET, then you cannot use the SDK. This isn't a huge loss though. The SDK is only a very slight wrapper around the XML files anyways. A docx file is just a zip with a bunch of XML files inside. There are some oddities in relationships between the files and where text is stored and how some things are referenced positionally instead of by ids, which is generally considered a very bad practice with XML. Regardless though, those issues are easily worked around and you can create .docx files manually without too much trouble. In fact, creating is much easier than reading.
The SDK is still useful in that it contains a file exploration tool that will give you a graphical explorer for existing files. When you want to know how to create particular content, do it within Word 2007, save the file, and then look at what the file contains.
来源:https://stackoverflow.com/questions/5813954/how-can-an-openoffice-document-be-created-in-c