|
发表于 2022-5-28 13:35:50
|
显示全部楼层
本楼为最佳答案
 - #include <windows.h>
- #include <combaseapi.h>
- #include <iostream>
- #import "C:\\Program Files\\Microsoft Office\\root\\Office16\\MSWORD.OLB" auto_search, auto_rename
- Word::WdColor rgb(unsigned char r, unsigned char g, unsigned char b) {
- return (Word::WdColor)((b << 16) | (g << 8) | r);
- }
- int main() {
- CoInitialize(NULL);
- Word::_ApplicationPtr Application(__uuidof(Word::Application));
- Application->Visible = true;
- Word::DocumentsPtr docs = Application->Documents;
- Word::_DocumentPtr doc = docs->Add();
- Word::RangePtr range = doc->Content;
- range->Text = "hello world!";
- Word::_FontPtr font(__uuidof(Word::Font));
- font->Color = Word::wdColorRose;
- font->Name = "Courier New";
- font->Bold = true;
- font->Size = 24;
- range->Font = font;
- range->Paragraphs->Alignment = Word::wdAlignParagraphCenter;
- #if 0
- range->Font->Color = rgb(255, 0, 0);
- range->Font->Color = rgb(0, 255, 0);
- range->Font->Color = rgb(0, 0, 255);
-
- range->Font->Color = rgb(255, 192, 203);
- range->Font->Color = rgb(218, 112, 214);
- range->Font->Color = rgb(123, 104, 238);
- #endif
- std::cin.get();
- Application->Quit(&variant_t(Word::wdDoNotSaveChanges));
- CoUninitialize();
- return 0;
- }
复制代码
|
|