没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:胡涛|2023-01-29 09:54:14.860|阅读 97 次
概述:在本文中,您将学习如何使用Aspose.Words for C++并使用 C++ 从头开始创建 MS Word 文档。欢迎查阅
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
Aspose.Words 是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,
Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
Aspose.Words是一个功能丰富的 API 集合,可让您以编程方式创建、编辑和转换 MS Word 文档。它为操作文字处理文档提供了广泛的基本和高级功能。在本文中,您将学习如何使用Aspose.Words for C++并使用 C++ 从头开始创建 MS Word 文档。分步指南和代码示例将让您了解如何在 Word 文档中插入文本、图像、表格、列表和其他元素。
Aspose.Words for C++允许您在没有 MS Word 的情况下在 C++ 应用程序中生成和操作文字处理文档。您可以通过以下命令使用NuGet下载API 或将其安装在您的 C++ 应用程序中。
PM> Install-Package Aspose.Words.Cpp
让我们首先创建一个简单的 Word 文档并将其另存为.doc或.docx文件。为此,您需要执行以下步骤:
以下代码示例显示了如何使用 C++ 创建 Word DOCX 文档。
// Initialize a Document. System::SharedPtr<Document> doc = System::MakeObject<Document>(); // Use a document builder to add content to the document. System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); // Add text builder->Writeln(u"Hello World!"); // Save the document to disk. doc->Save(u"document.docx");
您还可以使用 Aspose.Words for C++ 编辑现有的 Word 文档。为此,API 使用文档对象模型 (DOM) 作为文档的内存表示。DOM 允许您访问 Word 文档的元素,例如页眉/页脚、段落、表格等。在此处阅读有关 DOM 的更多信息。
要更新 Word 文档,只需使用Document类加载它并根据需要进行处理。以下是编辑和更新现有 Word 文档的步骤。
下面的代码示例显示了如何使用 C++ 更新 Word 文档中段落的文本。
// Initialize a Document. System::SharedPtr<Document> doc = System::MakeObject<Document>(u"document.docx"); // Use a document builder to add content to the document. System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); // Get section auto section = doc->get_Sections()->idx_get(0); // Get body auto body = section->get_Body(); // Get first paragraph auto para = body->get_FirstParagraph(); // Update text auto run = para->get_Runs()->idx_get(0); run->set_Text(u"This is the updated text."); // Save the document to disk. doc->Save(u"updated_document.docx");
以下是使用 C++ 在 MS Word 文档中插入图像的步骤。
下面的代码示例显示了如何使用 C++ 将图像插入到 Word 文档中。
System::SharedPtr<Document> doc = System::MakeObject<Document>(); System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); // Add a logo to the top left of the page. The image is placed in front of all other text. System::SharedPtr<Shape> shape = builder->InsertImage( u"Aspose Logo.png", RelativeHorizontalPosition::Page, 60.0, RelativeVerticalPosition::Page, 60.0, -1.0, -1.0, WrapType::None); doc->Save(u"document_with_image.docx");
表格是 Word 文档的重要元素,用于以行和列的形式保存数据。为了在 Word 文档中生成表格,请按照以下步骤操作。
以下代码示例显示如何使用 C++ 在 Word 文档中插入表格 。
System::SharedPtr<Document> doc = System::MakeObject<Document>(); System::SharedPtr<Table> table = System::MakeObject<Table>(doc); // Add the table to the document. doc->get_FirstSection()->get_Body()->AppendChild(table); System::SharedPtr<Row> row = System::MakeObject<Row>(doc); row->get_RowFormat()->set_AllowBreakAcrossPages(true); table->AppendChild(row); // We can now apply any auto fit settings. table->AutoFit(AutoFitBehavior::FixedColumnWidths); // Create a cell and add it to the row System::SharedPtr<Cell> cell = System::MakeObject<Cell>(doc); cell->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_LightBlue()); cell->get_CellFormat()->set_Width(80); // Add a paragraph to the cell as well as a new run with some text. cell->AppendChild(System::MakeObject<Paragraph>(doc)); cell->get_FirstParagraph()->AppendChild(System::MakeObject<Run>(doc, u"Row 1, Cell 1 Text")); // Add the cell to the row. row->AppendChild(cell); // We would then repeat the process for the other cells and rows in the table. // We can also speed things up by cloning existing cells and rows. row->AppendChild((System::StaticCast<Node>(cell))->Clone(false)); row->get_LastCell()->AppendChild(System::MakeObject<Paragraph>(doc)); row->get_LastCell()->get_FirstParagraph()->AppendChild(System::MakeObject<Run>(doc, u"Row 1, Cell 2 Text")); // Save the document to disk. doc->Save(u"document_with_table.docx");
最后但同样重要的是,在 Word 文档中创建一个列表。以下是创建项目符号列表的步骤。
以下代码示例显示如何使用 C++ 在 Word 文档中创建列表。
System::SharedPtr<Document> doc = System::MakeObject<Document>(); System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); // Create a numbered list based on one of the Microsoft Word list templates and // apply it to the current paragraph in the document builder. builder->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::NumberArabicDot)); // There are 9 levels in this list, lets try them all. for (int32_t i = 0; i < 9; i++) { builder->get_ListFormat()->set_ListLevelNumber(i); builder->Writeln(System::String(u"Level ") + i); } // Create a bulleted list based on one of the Microsoft Word list templates // and apply it to the current paragraph in the document builder. builder->get_ListFormat()->set_List(doc->get_Lists()->Add(ListTemplate::BulletDiamonds)); // There are 9 levels in this list, lets try them all. for (int32_t i = 0; i < 9; i++) { builder->get_ListFormat()->set_ListLevelNumber(i); builder->Writeln(System::String(u"Level ") + i); } // This is a way to stop list formatting. builder->get_ListFormat()->set_List(nullptr); // Save the document to disk. builder->get_Document()->Save(u"document_with_list.docx");
以上便是如何使用 C++ 创建 MS Word 文档 (DOC/DOCX) 步骤 ,要是您还有其他关于产品方面的问题,欢迎咨询我们,或者加入我们官方技术交流群。
欢迎下载|体验更多Aspose产品
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@wqylolg.cn
本文将为大家介绍DevExpress XAF如何将.NET Aspire集成到Blazor项目中,欢迎下载最新版组件体验!
JxBrowser是 TeamDev 开发的跨平台库,用于在 Java 应用程序中集成 Chromium 浏览器。它支持 HTML5、CSS3、JavaScript 等,具备硬件加速渲染、双向 Java 与 JavaScript 连接、丰富的事件监听等功能,能处理网页保存、打印等操作,助力 Java 应用高效展示和交互网页内容。
FastReport 不仅仅包含报表组件,它还提供更多功能!特别是,它有几个组件可以像其他 Delphi 组件一样在您的应用程序中使用,而且我们一直在向库中添加更多组件。在本文中,我们将介绍其中之一:TfrShellTreeView。
RFID 标签是一种现代化的产品识别方式,正在迅速取代条形码。RFID 标签的独特之处在于它使用无线电信号。这让您可以快速扫描大量物品,节省大量时间。RFID 标签也用于识别公司内部的员工。在本文中,我们将探讨 RFID 标签如何与FastReport VCL中新增的 TfrxDeviceCommand 对象配合使用。
专业的电子表格控件,无需MS Excel也可满足一切Excel表格功能。
Aspose.Words for .NET无需Microsoft Word也可在任何平台上满足Word文档的一切操作需求。
Aspose.PDF for .NETPDF文档创建组件,无需Adobe Acrobat,也可以在任何平台上操作PDF文档。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@wqylolg.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢