IronWord 开始 在 iOS 上使用 How to Use IronWord on iOS Kye Stuart 已更新:八月 21, 2025 Download IronWord NuGet 下载 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This article was translated from English: Does it need improvement? Translated View the article in English .NET MAUI (Multi-platform App UI) enables you to build native applications across Android, iOS, Windows, and macOS using a single .NET codebase. With IronWord, .NET developers can easily create, read, edit, and save Microsoft Word (.docx) documents — fully cross-platform and without requiring Microsoft Office. IronWord works seamlessly on iOS via the shared .NET MAUI codebase using the standard IronWord NuGet package — there is no platform-specific version needed. Install the IronWord NuGet Package IronWord is available as a standard cross-platform NuGet package and supports all major .NET MAUI targets, including iOS. Install-Package IronWord Create a .NET MAUI Project In Visual Studio: Go to File > New > Project. Under Multiplatform, select .NET MAUI App. Name your project (e.g., IronWordMauiIOS) and click Create. Add IronWord to Your Project You can add the package via NuGet Package Manager or by editing your .csproj file: <ItemGroup> <PackageReference Include="IronWord" Version="2025.5.0" /> </ItemGroup> <ItemGroup> <PackageReference Include="IronWord" Version="2025.5.0" /> </ItemGroup> XML You don’t need platform conditions — IronWord works across all targets automatically. Create the App Interface in XAML Add a simple UI to load, edit, and save Word documents. To do this, start by adding this code to the MainPage.xml code: <?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 This creates buttons and an editor UI for loading/saving Word content. Use IronWord in Shared Code In your MainPage.xaml.cs, implement reading and writing DOCX documents using IronWord: 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 Project File Overview Your project structure should now include: IronWordMauiIOS/ │ ├── MainPage.xaml ← UI Layout ├── MainPage.xaml.cs ← Logic for UI (Word document actions) ├── IronWordMauiIOS.csproj ← References IronWord NuGet package ├── Platforms/ios/ ← iOS-specific config (no changes needed here) └── ... Run the Project Set the target to iOS Simulator. Press Run. Test reading and writing .docx documents directly on your simulated iOS device. Final Notes Fully cross-platform (iOS, Android, Windows, macOS) No need for Microsoft Office or Interop 100% C# / .NET MAUI-native Works offline Excellent for building editors, resume builders, document viewers 常见问题解答 什么是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,展示各种功能和用例。 在iOS部署中IronWord是否需要额外的许可? IronWord在包括iOS应用程序在内的生产环境中部署需要有效的许可证。请确保检查许可条款以遵守使用指南。 Kye Stuart 立即与工程团队聊天 技术作家 Kye Stuart 在 Iron Software 中将编码热情与写作技能结合在一起。他在 Yoobee 学院接受软件部署教育,现在将复杂的技术概念转化为清晰的教育内容。Kye 重视终身学习,接受新的技术挑战。工作之余,他们喜欢 PC 游戏、Twitch 上的直播,以及户外活动如园艺和带狗 Jaiya 散步。Kye 的直截了当的方法使他们成为 Iron Software 使命的关键,即为全球开发者解密技术。 准备开始了吗? Nuget 下载 25,807 | 版本: 2025.11 刚刚发布 免费 NuGet 下载 总下载量:25,807 查看许可证