WEB开发网
开发学院软件开发C++ 在 C++ 程序中导出 Word 文档的方法 阅读

在 C++ 程序中导出 Word 文档的方法

 2008-03-08 21:56:30 来源:WEB开发网   
核心提示:假如您要在应用程序中处理Word文档,可以参考MSDN. Lori Turner. Automating Microsoft Office 97 and Office 2000,在 C++ 程序中导出 Word 文档的方法,该文内容具体全面,但是要在C++程序中导出Word文档,程序将生成一个Word文档,路径位于c:

  假如您要在应用程序中处理Word文档,可以参考MSDN. Lori Turner. Automating Microsoft Office 97 and Office 2000,该文内容具体全面,但是要在C++程序中导出Word文档,按照文中的方法来处理是很麻烦的,非凡是需要填写的参数太多,所以我们考虑生成正确的VB脚本,然后执行生成Word文档的操作,这个方法的优点在于:一方面可以少填写参数;另一方面可以使用在Word中录制的宏脚本,而只需作少量的修改。我们给出了一些简单的函数来方便生成Word文档(主要是简单的表格)和直接运行内存中的VB脚本,此外,还附带了一个小小的例子。

//创建Word文档 std::string create_new(); //保存Word文档 std::string close_save(const char* filename); //selection 往下移,以继续生成下一元素 std::string move_down(); //插入分段符 std::string put_Paragraph(); //添加标题 std::string put_title(const char* title, const char* title_type="标题 1", int align=ALIGN_LEFT); //添加“标题1” std::string put_title1(const char* title, int align=ALIGN_CENTER); //添加“标题2” std::string put_title2(const char* title, int align=ALIGN_LEFT); //添加“标题3” std::string put_title3(const char* title, int align=ALIGN_LEFT); //添加红色警告信息 std::string add_warning_msg(const char* msg="无数据"); //添加表格的一行数据(不用此函数) std::string add_grid_ln(const char* line); //添加表格 std::string put_grid(const char* content); //运行脚本 extern "C" void RunScript(const char* script_str); 下面是一个小例子,我们期望它在您的计算机上能够很好的运行,程序将生成一个Word文档,路径位于c:\test.doc,计算机上需要安装Word XP。 int main(int argc, char* argv[]) { ostringstream ostr; ostr<

Tags:程序 导出 Word

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接