IronWord 開始使用 用於iOS 如何在 iOS 上使用 IronWord Kye Stuart 更新:8月 21, 2025 下載 IronWord NuGet 下載 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在雙子座打開 請向 Gemini 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English .NET MAUI(多平台應用程式 UI)可讓您使用單一 .NET 程式碼庫建立跨 Android、iOS、Windows 和 macOS 的原生應用程式。 透過 IronWord,.NET 開發人員可以輕鬆建立、讀取、編輯和保存 Microsoft Word (.docx) 文件——完全跨平台,無需 Microsoft Office。 IronWord 透過共享的 .NET MAUI 程式碼庫,使用標準的 IronWord NuGet 套件,可以在 iOS 上無縫運行——無需特定於平台的版本。 安裝 IronWord NuGet 套件 IronWord 是一個標準的跨平台 NuGet 套件,支援所有主要的 .NET MAUI 目標平台,包括 iOS。 Install-Package IronWord 建立一個 .NET MAUI 項目 在 Visual Studio: 前往檔案 > 新建 > 專案。 在多平台下,選擇 .NET MAUI 應用程式。 為你的專案命名(例如,IronWordMauiIOS),然後點擊建立。 將 IronWord 加入您的專案中 您可以透過 NuGet 套件管理器新增套件,也可以透過編輯 .csproj 檔案新增: <ItemGroup> <PackageReference Include="IronWord" Version="2025.5.0" /> </ItemGroup> <ItemGroup> <PackageReference Include="IronWord" Version="2025.5.0" /> </ItemGroup> XML 您無需設定平台條件-IronWord 可自動在所有目標平台上執行。 在 XAML 中建立應用程式介面 新增一個簡單的使用者介面,用於載入、編輯和儲存 Word 文件。 為此,首先將以下程式碼加入MainPage.xml程式碼: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="IronWordMauiIOS.MainPage" BackgroundColor="White"> <VerticalStackLayout Padding="20" Spacing="15" VerticalOptions="Center"> <!-- Header --> <Label Text="IronWord iOS Demo" FontSize="24" FontAttributes="Bold" HorizontalOptions="Center" TextColor="#222"/> <!-- Open .docx --> <Button Text=" Open Word Document" Clicked="OpenDocx" BackgroundColor="#007AFF" TextColor="White" CornerRadius="10" HeightRequest="50"/> <!-- Editable content --> <Editor x:Name="docEditor" Placeholder="Start editing..." AutoSize="TextChanges" HeightRequest="250" FontSize="16" TextColor="#333" BackgroundColor="#F9F9F9" CornerRadius="10" Margin="0,10,0,0"/> <!-- Save Button --> <Button Text=" Save as .docx" Clicked="SaveDocx" BackgroundColor="#34C759" TextColor="White" CornerRadius="10" HeightRequest="50"/> <!-- Status message --> <Label x:Name="statusLabel" FontSize="14" TextColor="Gray" HorizontalOptions="Center"/> </VerticalStackLayout> </ContentPage> <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="IronWordMauiIOS.MainPage" BackgroundColor="White"> <VerticalStackLayout Padding="20" Spacing="15" VerticalOptions="Center"> <!-- Header --> <Label Text="IronWord iOS Demo" FontSize="24" FontAttributes="Bold" HorizontalOptions="Center" TextColor="#222"/> <!-- Open .docx --> <Button Text=" Open Word Document" Clicked="OpenDocx" BackgroundColor="#007AFF" TextColor="White" CornerRadius="10" HeightRequest="50"/> <!-- Editable content --> <Editor x:Name="docEditor" Placeholder="Start editing..." AutoSize="TextChanges" HeightRequest="250" FontSize="16" TextColor="#333" BackgroundColor="#F9F9F9" CornerRadius="10" Margin="0,10,0,0"/> <!-- Save Button --> <Button Text=" Save as .docx" Clicked="SaveDocx" BackgroundColor="#34C759" TextColor="White" CornerRadius="10" HeightRequest="50"/> <!-- Status message --> <Label x:Name="statusLabel" FontSize="14" TextColor="Gray" HorizontalOptions="Center"/> </VerticalStackLayout> </ContentPage> XML 這將建立用於載入/儲存 Word 內容的按鈕和編輯器使用者介面。 在共享程式碼中使用 IronWord 在 MainPage.xaml.cs 檔案中,使用 IronWord 實作 DOCX 文件的讀寫操作: using IronWord; using IronWord.Models; using Microsoft.Maui.Storage; using System.Text; namespace IronWordMauiIOS; public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); License.LicenseKey = "YOUR-LICENSE-KEY"; } private async void OpenDocx(object sender, EventArgs e) { try { var file = await FilePicker.PickAsync(); if (file == null) return; var path = Path.Combine(FileSystem.CacheDirectory, file.FileName); using (var source = await file.OpenReadAsync()) using (var target = File.Create(path)) await source.CopyToAsync(target); var doc = new WordDocument(path); docEditor.Text = ExtractText(doc); statusLabel.Text = "Document loaded successfully."; } catch (Exception ex) { statusLabel.Text = $"Error: {ex.Message}"; } } private async void SaveDocx(object sender, EventArgs e) { try { var document = new WordDocument(); var paragraph = new Paragraph(); paragraph.Texts.Add(new TextContent(docEditor.Text)); document.Paragraphs.Add(paragraph); var fileName = $"ExportedDoc_{DateTime.Now:yyyyMMddHHmmss}.docx"; var path = Path.Combine(FileSystem.AppDataDirectory, fileName); document.SaveAs(path); statusLabel.Text = $"Saved to: {fileName}"; } catch (Exception ex) { statusLabel.Text = $"Save error: {ex.Message}"; } } private string ExtractText(WordDocument doc) { var sb = new StringBuilder(); foreach (var para in doc.Paragraphs) { foreach (var element in para.Texts) { if (element is TextContent text) sb.AppendLine(text.Text); } } return sb.ToString(); } } using IronWord; using IronWord.Models; using Microsoft.Maui.Storage; using System.Text; namespace IronWordMauiIOS; public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); License.LicenseKey = "YOUR-LICENSE-KEY"; } private async void OpenDocx(object sender, EventArgs e) { try { var file = await FilePicker.PickAsync(); if (file == null) return; var path = Path.Combine(FileSystem.CacheDirectory, file.FileName); using (var source = await file.OpenReadAsync()) using (var target = File.Create(path)) await source.CopyToAsync(target); var doc = new WordDocument(path); docEditor.Text = ExtractText(doc); statusLabel.Text = "Document loaded successfully."; } catch (Exception ex) { statusLabel.Text = $"Error: {ex.Message}"; } } private async void SaveDocx(object sender, EventArgs e) { try { var document = new WordDocument(); var paragraph = new Paragraph(); paragraph.Texts.Add(new TextContent(docEditor.Text)); document.Paragraphs.Add(paragraph); var fileName = $"ExportedDoc_{DateTime.Now:yyyyMMddHHmmss}.docx"; var path = Path.Combine(FileSystem.AppDataDirectory, fileName); document.SaveAs(path); statusLabel.Text = $"Saved to: {fileName}"; } catch (Exception ex) { statusLabel.Text = $"Save error: {ex.Message}"; } } private string ExtractText(WordDocument doc) { var sb = new StringBuilder(); foreach (var para in doc.Paragraphs) { foreach (var element in para.Texts) { if (element is TextContent text) sb.AppendLine(text.Text); } } return sb.ToString(); } } Imports IronWord Imports IronWord.Models Imports Microsoft.Maui.Storage Imports System.Text Namespace IronWordMauiIOS Partial Public Class MainPage Inherits ContentPage Public Sub New() InitializeComponent() License.LicenseKey = "YOUR-LICENSE-KEY" End Sub Private Async Sub OpenDocx(ByVal sender As Object, ByVal e As EventArgs) Try Dim file = Await FilePicker.PickAsync() If file Is Nothing Then Return End If Dim path As System.String = System.IO.Path.Combine(FileSystem.CacheDirectory, file.FileName) Using source = Await file.OpenReadAsync() Using target = System.IO.File.Create(path) Await source.CopyToAsync(target) End Using End Using Dim doc = New WordDocument(path) docEditor.Text = ExtractText(doc) statusLabel.Text = "Document loaded successfully." Catch ex As Exception statusLabel.Text = $"Error: {ex.Message}" End Try End Sub Private Async Sub SaveDocx(ByVal sender As Object, ByVal e As EventArgs) Try Dim document = New WordDocument() Dim paragraph As New Paragraph() paragraph.Texts.Add(New TextContent(docEditor.Text)) document.Paragraphs.Add(paragraph) Dim fileName = $"ExportedDoc_{DateTime.Now:yyyyMMddHHmmss}.docx" Dim path As System.String = System.IO.Path.Combine(FileSystem.AppDataDirectory, fileName) document.SaveAs(path) statusLabel.Text = $"Saved to: {fileName}" Catch ex As Exception statusLabel.Text = $"Save error: {ex.Message}" End Try End Sub Private Function ExtractText(ByVal doc As WordDocument) As String Dim sb = New StringBuilder() For Each para In doc.Paragraphs For Each element In para.Texts Dim tempVar As Boolean = TypeOf element Is TextContent Dim text As TextContent = If(tempVar, CType(element, TextContent), Nothing) If tempVar Then sb.AppendLine(text.Text) End If Next element Next para Return sb.ToString() End Function End Class End Namespace $vbLabelText $csharpLabel 專案文件概覽 您的專案結構現在應該包括: IronWordMauiIOS/ │ ├── MainPage.xaml ← UI 佈局 ├── MainPage.xaml.cs ← 使用者介面邏輯(Word 文件操作) ├── IronWordMauiIOS.csproj ← 引用 IronWord NuGet 包 ├── Platforms/ios/ ← iOS 特定配置(此處無需更改) └── ... 運行專案 將目標設定為 iOS 模擬器。 按下運行鍵。 在模擬 iOS 裝置上直接測試讀取和寫入 .docx 文件。 最後說明 完全跨平台(iOS、Android、Windows、macOS) 無需 Microsoft Office 或 Interop 100% C# / .NET MAUI 原生 可離線使用 非常適合用於建立編輯器、簡歷產生器和文件檢視器 常見問題解答 什麼是 IronWord,它如何在 iOS 上使用? IronWord 是一個強大的函式庫,專為處理 .NET 應用程式中的 Word 文件而設計,包括 iOS。它允許開發人員在移動應用程式中無縫創建、操作和轉換 Word 文件。 如何將 IronWord 整合到我的 iOS 專案中? 要將 IronWord 整合到 iOS 專案中,您需要將 IronWord 函式庫添加到您的 .NET 解決方案中,配置專案以引用它,並使用提供的 API 管理 Word 文件。 在 iOS 上使用 IronWord 的系統要求是什麼? IronWord 需要在您的 iOS 開發環境中具備兼容的 .NET 環境。確保您的開發環境已更新並支持必要的框架以實現無縫整合。 IronWord 能否在 iOS 上將 Word 文件轉換為其他格式? 可以,IronWord 能夠在 iOS 應用程式中將 Word 文件轉換為多種格式,如 PDF,使文件處理和共享更具靈活性。 IronWord 支持在 iOS 上進行文件操作嗎? 當然,IronWord 支持廣泛的文件操作,包括編輯文本、插入圖片和管理文件屬性,直接在 iOS 應用程式中進行。 是否可以使用 IronWord 在 iOS 上從頭創建 Word 文件? 是的,IronWord 允許您在 iOS 上從頭創建新的 Word 文件,提供一整套工具以程式化地添加內容、格式和樣式。 IronWord 如何在 iOS 應用程式中處理 Word 文件安全問題? IronWord 包含管理文件安全性的功能,如密碼保護和加密,確保您的 Word 文件在 iOS 應用中保持安全。 是否有可用於在 iOS 上使用 IronWord 的樣本專案? 是的,Iron Software 提供樣本專案和文檔,以幫助開發人員快速開始在 iOS 上使用 IronWord,展示多種功能和使用案例。 IronWord 是否需額外許可才能在 iOS 上部署? IronWord 需要有效許可才能在生產環境中部署,包括 iOS 應用程式。請確保檢查許可條款以符合使用準則。 Kye Stuart 立即與工程團隊聊天 技術作家 Kye Stuart 在 Iron Software 將編碼熱情與寫作技能相結合。接受過 Yoobee 學院的软件部署教育,他現在將複雜的技術概念轉化為清晰的教育內容。Kye 重視終身學習,並接受新技術挑戰。在工作之外,他喜歡 PC 遊戲,並在 Twitch 上進行直播,以及喜好戶外活動如園藝和遛狗 (Jaiya)。Kye 的直截了當風格,使他成為 Iron Software 全球解密技術使命的關鍵人物。 準備好開始了嗎? Nuget 下載 27,129 | Version: 2025.11 剛發表 免費下載 NuGet 下載總數:27,129 檢視授權