在Visual Studio 2005中从C ++创建Microsoft Word文档

时间:2022-09-01 20:56:16

We got a homework assignment to create a Microsoft Word document using Visual Studio 2005 and C++. Could anyone explain how this could be done. I was trying to do it using VSTO, but I've had no luck. All resources on the internet I could find explain how this could be done in VB or C#, but I need some C++ examples. Thanks

我们完成了一项使用Visual Studio 2005和C ++创建Microsoft Word文档的作业。任何人都可以解释如何做到这一点。我试图用VSTO做这件事,但我没有运气。我可以找到互联网上的所有资源,解释如何在VB或C#中完成,但我需要一些C ++示例。谢谢

EDIT: Accepted format is .doc.

编辑:接受的格式是.doc。

5 个解决方案

#1


Apparently VSTO is not available for C++.

显然VSTO不适用于C ++。

Does this MSDN article help?:

这篇MSDN文章是否有帮助?:

#2


Take a look at Use OLE Automation from a C Application Rather Than C++. That will show you the plain way to access the OLE automation interface for Word.

看看从C应用程序而不是C ++使用OLE自动化。这将显示访问Word的OLE自动化界面的简单方法。

For methods, properties, use the Object Browser which you can access by selecting Tools -> Macro -> Visual Basic Editor. Press F2 to invoke the object browser.

对于方法,属性,使用可以通过选择工具 - >宏 - > Visual Basic编辑器访问的对象浏览器。按F2键调用对象浏览器。

#3


I think this might help: Creating, opening and printing a word file from C++

我认为这可能会有所帮助:从C ++创建,打开和打印word文件

Please check especially the main function on example 2 since there it is shown how to start Word and make it visible.

请特别检查示例2中的主要功能,因为它显示了如何启动Word并使其可见。

#4


You can do this using Mircosoft Office's Primary Interop Assemblies. Doing this with C++ is not as difficult as it seems. you need to turn on Common Language Runtime support from project properties and then you can simply do a #using statement on the Mircosoft.Office.Interop.dll.

您可以使用Mircosoft Office的主互操作程序集执行此操作。使用C ++执行此操作并不像看起来那么困难。您需要从项目属性启用公共语言运行时支持,然后您只需在Mircosoft.Office.Interop.dll上执行#using语句。

After that you should be OK to use the interop assembly as you want. In C++, you access .NET classes a little different i.e., replacing . with :: Something like...

之后,您可以根据需要使用互操作程序集。在C ++中,您可以访问一些不同的.NET类,即替换。 with ::像...一样的东西

Microsoft::Office::Interop::Word^ wordObj = new Microsoft::Office::Interop::Word();

Microsoft :: Office :: Interop :: Word ^ wordObj = new Microsoft :: Office :: Interop :: Word();

Microsoft Office 2003 PIAs
Microsoft Office 2007 PIAs

Microsoft Office 2003 PIA Microsoft Office 2007 PIA

#5


Here is a spec of the binary Word document format. You could easily roll your own implementation.

这是二进制Word文档格式的规范。您可以轻松地推出自己的实现。

http://www.microsoft.com/interop/docs/OfficeBinaryFormats.mspx

#1


Apparently VSTO is not available for C++.

显然VSTO不适用于C ++。

Does this MSDN article help?:

这篇MSDN文章是否有帮助?:

#2


Take a look at Use OLE Automation from a C Application Rather Than C++. That will show you the plain way to access the OLE automation interface for Word.

看看从C应用程序而不是C ++使用OLE自动化。这将显示访问Word的OLE自动化界面的简单方法。

For methods, properties, use the Object Browser which you can access by selecting Tools -> Macro -> Visual Basic Editor. Press F2 to invoke the object browser.

对于方法,属性,使用可以通过选择工具 - >宏 - > Visual Basic编辑器访问的对象浏览器。按F2键调用对象浏览器。

#3


I think this might help: Creating, opening and printing a word file from C++

我认为这可能会有所帮助:从C ++创建,打开和打印word文件

Please check especially the main function on example 2 since there it is shown how to start Word and make it visible.

请特别检查示例2中的主要功能,因为它显示了如何启动Word并使其可见。

#4


You can do this using Mircosoft Office's Primary Interop Assemblies. Doing this with C++ is not as difficult as it seems. you need to turn on Common Language Runtime support from project properties and then you can simply do a #using statement on the Mircosoft.Office.Interop.dll.

您可以使用Mircosoft Office的主互操作程序集执行此操作。使用C ++执行此操作并不像看起来那么困难。您需要从项目属性启用公共语言运行时支持,然后您只需在Mircosoft.Office.Interop.dll上执行#using语句。

After that you should be OK to use the interop assembly as you want. In C++, you access .NET classes a little different i.e., replacing . with :: Something like...

之后,您可以根据需要使用互操作程序集。在C ++中,您可以访问一些不同的.NET类,即替换。 with ::像...一样的东西

Microsoft::Office::Interop::Word^ wordObj = new Microsoft::Office::Interop::Word();

Microsoft :: Office :: Interop :: Word ^ wordObj = new Microsoft :: Office :: Interop :: Word();

Microsoft Office 2003 PIAs
Microsoft Office 2007 PIAs

Microsoft Office 2003 PIA Microsoft Office 2007 PIA

#5


Here is a spec of the binary Word document format. You could easily roll your own implementation.

这是二进制Word文档格式的规范。您可以轻松地推出自己的实现。

http://www.microsoft.com/interop/docs/OfficeBinaryFormats.mspx