鱼C论坛

 找回密码
 立即注册
查看: 3624|回复: 16

[已解决]C++操作docx文档----高价求助

[复制链接]
发表于 2022-5-28 13:35:50 | 显示全部楼层    本楼为最佳答案   
  1. #include <windows.h>
  2. #include <combaseapi.h>
  3. #include <iostream>

  4. #import "C:\\Program Files\\Microsoft Office\\root\\Office16\\MSWORD.OLB" auto_search, auto_rename

  5. Word::WdColor rgb(unsigned char r, unsigned char g, unsigned char b) {
  6.     return (Word::WdColor)((b << 16) | (g << 8) | r);
  7. }

  8. int main() {
  9.     CoInitialize(NULL);
  10.     Word::_ApplicationPtr Application(__uuidof(Word::Application));
  11.     Application->Visible = true;
  12.     Word::DocumentsPtr docs = Application->Documents;
  13.     Word::_DocumentPtr doc = docs->Add();
  14.     Word::RangePtr range = doc->Content;

  15.     range->Text = "hello world!";

  16.     Word::_FontPtr font(__uuidof(Word::Font));
  17.     font->Color = Word::wdColorRose;
  18.     font->Name = "Courier New";
  19.     font->Bold = true;
  20.     font->Size = 24;
  21.     range->Font = font;

  22.     range->Paragraphs->Alignment = Word::wdAlignParagraphCenter;


  23. #if 0
  24.     range->Font->Color = rgb(255, 0, 0);
  25.     range->Font->Color = rgb(0, 255, 0);
  26.     range->Font->Color = rgb(0, 0, 255);
  27.    
  28.     range->Font->Color = rgb(255, 192, 203);
  29.     range->Font->Color = rgb(218, 112, 214);
  30.     range->Font->Color = rgb(123, 104, 238);
  31. #endif

  32.     std::cin.get();
  33.     Application->Quit(&variant_t(Word::wdDoNotSaveChanges));
  34.     CoUninitialize();
  35.     return 0;
  36. }
复制代码


1.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-6-9 00:55:51 | 显示全部楼层
烂泥化刚 发表于 2022-6-8 16:54
大佬可以请您详细讲一下吗?
#include
#include

先学这个
https://fishc.com.cn/forum-255-1.html
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-6-9 19:56:08 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-6-14 22:18:08 | 显示全部楼层
贾政景 发表于 2022-6-9 22:08
这个应该是靠电脑安装了office提供了相应的函数接口,有没有可以移植的方法啊,最后生成的exe能移植到其 ...

我没有找到这样的方法
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-23 04:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表