Erste Schritte mit IronWord
IronWord: Word-Dokument-Bibliothek für .NET
IronWord ist eine Word-Dokument-Bibliothek entwickelt von Iron Software. IronWord bietet eine robuste Funktionalität zum Arbeiten mit Word-Dokumenten in .NET-Anwendungen.
- Laden, Bearbeiten und Speichern von Word- und Docx-Dokumenten.
PageSetup: Konfigurieren der Papiergröße, Seitenorientierung, Ränder und Hintergrundfarbe.TextRun: Handhabung von Textinhalten, Stilen, Aufteilen, Hinzufügen von Text und Bildern.TextStyle: Verwaltung von Schriftfamilie, Größe, Farbe, fett, kursiv, durchgestrichen, unterstrichen, Hoch- und Tiefstellung.Paragraph: Hinzufügen von Textläufen, Bildern, Formen, Festlegen von Stilen, Ausrichtungen, Aufzählungs- und Nummerierungsliste.Table: Manipulation der Tabellenstruktur, einschließlich Hinzufügen von Zeilen, Abrufen und Festlegen von Zellwerten, Entfernen von Zeilen, Zusammenführen von Zellen und mehr.Image: Laden von Bildern aus Dateien oder Streams, Festlegen von Textumbruch, Positionsversatz, Breite, Höhe und andere Eigenschaften.Shape: Festlegen von Textumbruch, Positionsversatz, Breite, Höhe, Formtyp und Drehung.
Word-Dokument-C#-Bibliothek für .NET
- Laden Sie die C#-Bibliothek zum Verarbeiten von DOCX-Dokumenten herunter
- Word- und DOCX-Dokumente erstellen und bearbeiten
- Fügen Sie Dokumentstrukturen wie Absätze, Abschnitte und Tabellen hinzu.
- Fügen Sie Dokumentelemente wie Textabschnitte, Bilder und Formen hinzu.
- Gestalten Sie die Dokumentelemente ganz einfach
Installation
IronWord-Bibliothek
Die Installation von IronWord ist schnell und einfach. Sie können das Paket mit NuGet mit folgendem Befehl installieren:
Alternativ können Sie direkt von der offiziellen IronWord NuGet-Website herunterladen.
Sobald sie installiert ist, können Sie beginnen, indem Sie using IronWord; am Anfang Ihrer C#-Code-Datei hinzufügen.
Lizenzschlüssel anwenden
Als Nächstes wenden Sie einen gültigen Lizenz- oder Testschlüssel auf IronWord an, indem Sie den Lizenzschlüssel der LicenseKey Eigenschaft der License Klasse zuweisen. Fügen Sie den folgenden Code direkt nach der Importerklärung hinzu, bevor Sie irgendwelche IronWord-Methoden verwenden:
using IronWord;
// Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE";Imports IronWord
' Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE"Imports IronWord
' Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE"Beispiele für Code
Lassen Sie uns einige Codebeispiele und die verfügbaren Funktionen erkunden.
- 'Datei' > 'Informationen' wählen und auf "Konvertieren" klicken.
- Sie erhalten eine Meldung, dass Ihr Dokument in das neueste Dateiformat aktualisiert wird. Auf "OK" klicken.
Erstellen von Word- und Docx-Dokumenten
Erstellen Sie das Word-Dokument, indem Sie die WordDocument Klasse mit einem ihrer Konstruktoren instanziieren. Danach nutzen Sie die SaveAs Methode, um das Word-Dokument zu exportieren. Beispiel:
using IronWord;
class Program
{
static void Main()
{
// Create a new Word document
var document = new WordDocument();
// Save the document as a .docx file
document.SaveAs("example.docx");
}
}using IronWord;
class Program
{
static void Main()
{
// Create a new Word document
var document = new WordDocument();
// Save the document as a .docx file
document.SaveAs("example.docx");
}
}Imports IronWord
Friend Class Program
Shared Sub Main()
' Create a new Word document
Dim document = New WordDocument()
' Save the document as a .docx file
document.SaveAs("example.docx")
End Sub
End ClassImports IronWord
Friend Class Program
Shared Sub Main()
' Create a new Word document
Dim document = New WordDocument()
' Save the document as a .docx file
document.SaveAs("example.docx")
End Sub
End ClassBild hinzufügen
Ein Bild kann nicht alleine hinzugefügt werden; Stattdessen sollte es zu einer der Dokumentstrukturen hinzugefügt werden, wie zum Beispiel Paragraph, TableCell oder Section. Verwenden Sie die AddImage Methode, um ein Bild hinzuzufügen. Beispiel:
using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = new DocumentSection();
document.AddSection(section);
// Add an image to a paragraph
var paragraph = new Paragraph();
section.AddParagraph(paragraph);
paragraph.AddImage(new ImageContent("path/to/image.jpg") { Width = 100, Height = 100 });
document.SaveAs("example_with_image.docx");
}
}using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = new DocumentSection();
document.AddSection(section);
// Add an image to a paragraph
var paragraph = new Paragraph();
section.AddParagraph(paragraph);
paragraph.AddImage(new ImageContent("path/to/image.jpg") { Width = 100, Height = 100 });
document.SaveAs("example_with_image.docx");
}
}Imports IronWord
Imports IronWord.Models
Class Program
Shared Sub Main()
Dim document = New WordDocument()
Dim section = New DocumentSection()
document.AddSection(section)
' Add an image to a paragraph
Dim paragraph = New Paragraph()
section.AddParagraph(paragraph)
paragraph.AddImage(New ImageContent("path/to/image.jpg") With {.Width = 100, .Height = 100})
document.SaveAs("example_with_image.docx")
End Sub
End ClassImports IronWord
Imports IronWord.Models
Class Program
Shared Sub Main()
Dim document = New WordDocument()
Dim section = New DocumentSection()
document.AddSection(section)
' Add an image to a paragraph
Dim paragraph = New Paragraph()
section.AddParagraph(paragraph)
paragraph.AddImage(New ImageContent("path/to/image.jpg") With {.Width = 100, .Height = 100})
document.SaveAs("example_with_image.docx")
End Sub
End ClassTabelle hinzufügen
Das Hinzufügen einer Tabelle erfordert das Erstellen von Tabelle, Zeilen, Spalten und Tabellenzellen. Dies bietet erhebliche Konfigurationsmöglichkeiten, da jede Zelle unterschiedliche Stile haben kann. Beispiel:
using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = new DocumentSection();
document.AddSection(section);
var table = new Table(3, 3); // 3x3 table
section.AddTable(table);
// Iterate over cells and set their content
for (int i = 0; i < table.Rows.Count; i++)
{
for (int j = 0; j < table.Rows[i].Cells.Count; j++)
{
((TableCell)table.Rows[i].Cells[j]).AddParagraph(new Paragraph(new TextContent($"Cell {i+1},{j+1}")));
}
}
document.SaveAs("example_with_table.docx");
}
}using IronWord;
using IronWord.Models;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = new DocumentSection();
document.AddSection(section);
var table = new Table(3, 3); // 3x3 table
section.AddTable(table);
// Iterate over cells and set their content
for (int i = 0; i < table.Rows.Count; i++)
{
for (int j = 0; j < table.Rows[i].Cells.Count; j++)
{
((TableCell)table.Rows[i].Cells[j]).AddParagraph(new Paragraph(new TextContent($"Cell {i+1},{j+1}")));
}
}
document.SaveAs("example_with_table.docx");
}
}Imports IronWord
Imports IronWord.Models
Class Program
Shared Sub Main()
Dim document As New WordDocument()
Dim section As New DocumentSection()
document.AddSection(section)
Dim table As New Table(3, 3) ' 3x3 table
section.AddTable(table)
' Iterate over cells and set their content
For i As Integer = 0 To table.Rows.Count - 1
For j As Integer = 0 To table.Rows(i).Cells.Count - 1
CType(table.Rows(i).Cells(j), TableCell).AddParagraph(New Paragraph(New TextContent($"Cell {i + 1},{j + 1}")))
Next
Next
document.SaveAs("example_with_table.docx")
End Sub
End ClassImports IronWord
Imports IronWord.Models
Class Program
Shared Sub Main()
Dim document As New WordDocument()
Dim section As New DocumentSection()
document.AddSection(section)
Dim table As New Table(3, 3) ' 3x3 table
section.AddTable(table)
' Iterate over cells and set their content
For i As Integer = 0 To table.Rows.Count - 1
For j As Integer = 0 To table.Rows(i).Cells.Count - 1
CType(table.Rows(i).Cells(j), TableCell).AddParagraph(New Paragraph(New TextContent($"Cell {i + 1},{j + 1}")))
Next
Next
document.SaveAs("example_with_table.docx")
End Sub
End ClassLizenzierung & Support verfügbar
IronWord ist eine kostenpflichtige Bibliothek; Testlizenzen sind jedoch kostenlos hier verfügbar.
Für weitere Informationen über Iron Software besuchen Sie bitte unsere Website: https://ironsoftware.com/. Für weitere Unterstützung und Anfragen wenden Sie sich bitte an unser Team.
Unterstützung von Iron Software
Für allgemeinen Support und technische Anfragen kontaktieren Sie uns bitte per E-Mail: support@ironsoftware.com
Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender Handbücher.