C# 获取 Word 项目列表 (List Galleries) 数量的 5 种方法
C# 获取 Word 项目列表 (List Galleries) 数量的 5 种方法
本文介绍了使用 C# 获取 Word 文档中项目列表 (List Galleries) 数量的 5 种方法,包括使用 Microsoft.Office.Interop.Word、Open XML SDK、Aspose.Words、Spire.Doc 和 GemBox.Document 库。
1. 使用 Microsoft.Office.Interop.Word 命名空间
using Microsoft.Office.Interop.Word;
Application wordApp = new Application();
ListGalleries listGalleries = wordApp.ListGalleries;
int count = listGalleries.Count;
2. 使用 Open XML SDK
using DocumentFormat.OpenXml.Wordprocessing;
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open('Document.docx', true))
{
ListGallery listGallery = wordDoc.MainDocumentPart.DocumentSettingsPart.Settings.Descendants<ListGallery>().FirstOrDefault();
int count = listGallery.Count;
}
3. 使用 Aspose.Words
using Aspose.Words;
Document doc = new Document('Document.docx');
ListGalleries listGalleries = doc.ListGalleries;
int count = listGalleries.Count;
4. 使用 Spire.Doc
using Spire.Doc;
Document doc = new Document();
ListGallery listGallery = doc.ListGalleries;
int count = listGallery.Count;
5. 使用 GemBox.Document
using GemBox.Document;
DocumentModel document = DocumentModel.Load('Document.docx');
ListGallery listGallery = document.Settings.ListGallery;
int count = listGallery.Count;
原文地址: https://www.cveoy.top/t/topic/o0fG 著作权归作者所有。请勿转载和采集!