LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

OfficeIMO - 為 .NET 開發者打造的輕量級 Word 文檔操作庫

admin
2025年6月24日 17:33 本文熱度 29

簡介

OfficeIMO 是一個用于創建和操作 Microsoft Word (.docx) 和 Excel (.xlsx) 文檔的 .NET 庫。它基于 OpenXML SDK,提供了更簡單直觀的 API 接口。

OfficeIMO 的設計理念是簡單高效。專注于基本的 Word 處理需求,對于需要直接處理 Word 文檔而不需要功能豐富的復雜庫的項目來說,它是一個理想的選擇。

該項目最初是為了簡化 PowerShell 模塊 PSWriteOffice 中的文檔生成流程而開發,現已成為適用于整個 .NET 社區的通用庫。

平臺支持與兼容性

平臺
支持版本
Windows
.NET Framework 4.7.2+、.NET Core 3.1+、.NET 5/6/7/8/9
Linux
.NET Core 3.1+、.NET 5/6/7/8/9
macOS
.NET Core 3.1+、.NET 5/6/7/8/9

測試覆蓋率Codecov 鏈接
持續集成狀態GitHub Actions CI

核心功能列表

Word 功能

  • ? ?? 創建、加載、保存文檔
  • ? ?? 設置文檔屬性(標題、作者、關鍵詞等)
  • ? ?? 添加段落并設置樣式(加粗、顏色、對齊方式)
  • ? ?? 表格操作(添加行/列、合并單元格、設置邊框)
  • ? ?? 插入圖片(文件、Base64)
  • ? ?? 超鏈接、書簽、分頁符、注釋
  • ? ?? 內容控件(StructuredDocumentTag)
  • ? ?? 圖表、形狀、水印、封面頁
  • ? ?? 嵌入 HTML、RTF、TXT 文件
  • ? ?? 自動生成目錄(TOC)

使用示例

Nuget安裝

dotnet add package OfficeIMO.Word

基礎文檔創建

string filePath = Path.Combine("Support""GitHub""PSWriteOffice""Examples""Documents""BasicDocument.docx");

using (WordDocument document = WordDocument.Create(filePath)) {
    document.Title = "This is my title";
    document.Creator = "Przemys?aw K?ys";
    document.Keywords = "word, docx, test";

    var paragraph = document.AddParagraph("Basic paragraph");
    paragraph.ParagraphAlignment = JustificationValues.Center;
    paragraph.Color = SixLabors.ImageSharp.Color.Red;

    document.Save(true);
}

流式文檔操作

using var stream = new MemoryStream();
using (var document = WordDocument.Create(stream)) {
    document.AddParagraph("Stream based document");
    document.Save(stream);
}

stream.Position = 0;
using (var loaded = WordDocument.Load(stream)) {
    Console.WriteLine(loaded.Paragraphs[0].Text);
}

保存為新文檔

using (WordDocument document = WordDocument.Create()) {
    document.AddParagraph("Some text");
    using var copy = document.SaveAs(filePath);
    // document.FilePath 仍然是 null
    // copy.FilePath 等于 filePath
}

頁眉頁腳設置

using (WordDocument document = WordDocument.Create(filePath)) {
    document.Sections[0].PageOrientation = PageOrientationValues.Landscape;
    document.AddParagraph("Test Section0");
    document.AddHeadersAndFooters();
    document.DifferentFirstPage = true;
    document.DifferentOddAndEvenPages = true;

    document.Sections[0].Header.First.AddParagraph().SetText("Test Section 0 - First Header");
    document.Sections[0].Header.Default.AddParagraph().SetText("Test Section 0 - Header");
    document.Sections[0].Header.Even.AddParagraph().SetText("Test Section 0 - Even");

    document.AddPageBreak();
    // ... 其他節配置 ...
    document.Save(true);
}

內容控件操作

using (WordDocument document = WordDocument.Create(filePath)) {
    var sdt = document.AddStructuredDocumentTag("Hello""MyAlias""MyTag");
    sdt.Text = "Changed";
    document.Save(true);
}

using (WordDocument document = WordDocument.Load(filePath)) {
    var tag = document.GetStructuredDocumentTagByTag("MyTag");
    Console.WriteLine(tag.Text);
}

該文章在 2025/6/26 22:14:26 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved

黄频国产免费高清视频,久久不卡精品中文字幕一区,激情五月天AV电影在线观看,欧美国产韩国日本一区二区
亚洲日本人在线看片 | 午夜福利小草久久99 | 亚洲А∨天堂AV网在线 | 色偷偷香蕉人人澡 | 思思久热精品视频 | 五月天Av在线进入不卡 |