Rozpoczęcie Pracy z IronWord
IronWord: Biblioteka Dokumentów Word dla .NET
IronWord to biblioteka dokumentów Word opracowana przez Iron Software. IronWord doskonali się w zapewnianiu solidnej funkcjonalności do pracy z dokumentami Word w aplikacjach .NET.
- Ładowanie, manipulowanie i zapisywanie dokumentów Word i Docx.
PageSetup: Konfiguracja rozmiaru papieru, orientacji strony, marginesów i koloru tła.TextRun: Obsługa treści tekstowych, stylów, dzielenia, dołączania tekstu i dodawania obrazów.TextStyle: Zarządzanie rodziną czcionek, rozmiarem, kolorem, pogrubieniem, kursywą, przekreśleniem, podkreśleniem, indeksem górnym i dolnym.Paragraph: Dodawanie ciągów tekstowych, obrazów, kształtów, ustawianie stylów, wyrównania, punktorów i list numerowanych.Table: Manipulowanie strukturą tabeli, w tym dodawanie wierszy, pobieranie i ustawianie wartości komórek, usuwanie wierszy, scalanie komórek i inne operacje.Image: Ładowanie obrazów z plików lub strumieni, ustawianie zawijania tekstu, przesunięcia pozycji, szerokości, wysokości i innych właściwości.Shape: Ustawianie zawijania tekstu, przesunięcia pozycji, szerokości, wysokości, typu kształtu i obrotu.
Biblioteka C# dotycząca dokumentów Word dla .NET
- Pobierz bibliotekę C# do obsługi dokumentów DOCX
- Tworzenie i modyfikowanie dokumentów Word i DOCX
- Dodawanie struktur dokumentu takich jak akapity, sekcje i tabele
- Dodawanie elementów dokumentu takich jak przebiegi tekstu, obrazy i kształty
- Stylizowanie elementów dokumentu z łatwością
Instalacja
Biblioteka IronWord
Instalacja IronWord jest szybka i prosta. Możesz zainstalować pakiet używając NuGet z następującą komendą:
Install-Package IronWord
Alternatywnie, pobierz bezpośrednio z oficjalnej strony NuGet IronWord.
Po zainstalowaniu możesz rozpocząć pracę, dodając using IronWord; na początku pliku kodu C#.
Stosowanie klucza licencyjnego
Następnie zastosuj ważną licencję lub klucz próbny do IronWord, przypisując klucz licencyjny do właściwości LicenseKey klasy License. Dołącz następujący kod zaraz po instrukcji importu, zanim użyjesz jakichkolwiek metod IronWord:
using IronWord;
// Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE";
using IronWord;
// Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE";
Imports IronWord
' Assign your license key
License.LicenseKey = "YOUR_LICENSE_KEY_HERE"
Przykłady kodu
Przeanalizujmy teraz kilka przykładów kodu i dostępnych funkcji.
- Wybierz 'Plik' > 'Informacje' i kliknij "Konwertuj."
- Otrzymasz komunikat informujący, że twój dokument zostanie zaktualizowany do najnowszego formatu pliku. Kliknij "OK."
Tworzenie dokumentów Word i Docx
Utwórz dokument WORD, instancjonując klasę WordDocument przy użyciu jednego z jej konstruktorów. Następnie należy użyć metody SaveAs, aby wyeksportować dokument WORD. Przykład:
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 Class
Dodaj obraz
Obrazu nie można dodać samodzielnie; zamiast tego należy go dodać do jednej ze struktur dokumentu, takich jak Paragraph, TableCell lub Section. Użyj metody AddImage, aby dodać obraz. Przykład:
using IronWord;
using System.Drawing;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = document.Sections.Add();
// Add an image to a paragraph
var paragraph = section.Paragraphs.Add();
paragraph.AddImage("path/to/image.jpg", new Rectangle(0, 0, 100, 100));
document.SaveAs("example_with_image.docx");
}
}
using IronWord;
using System.Drawing;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = document.Sections.Add();
// Add an image to a paragraph
var paragraph = section.Paragraphs.Add();
paragraph.AddImage("path/to/image.jpg", new Rectangle(0, 0, 100, 100));
document.SaveAs("example_with_image.docx");
}
}
Imports IronWord
Imports System.Drawing
Friend Class Program
Shared Sub Main()
Dim document = New WordDocument()
Dim section = document.Sections.Add()
' Add an image to a paragraph
Dim paragraph = section.Paragraphs.Add()
paragraph.AddImage("path/to/image.jpg", New Rectangle(0, 0, 100, 100))
document.SaveAs("example_with_image.docx")
End Sub
End Class
Dodaj Tabelę
Dodanie tabeli wymaga utworzenia tabeli, wierszy, kolumn oraz komórek tabeli. To umożliwia znaczące możliwości konfiguracji, ponieważ każda komórka może mieć różne style. Przykład:
using IronWord;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = document.Sections.Add();
var table = section.Tables.Add(3, 3); // 3x3 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++)
{
table.Rows[i].Cells[j].Paragraphs.Add().AppendText($"Cell {i+1},{j+1}");
}
}
document.SaveAs("example_with_table.docx");
}
}
using IronWord;
class Program
{
static void Main()
{
var document = new WordDocument();
var section = document.Sections.Add();
var table = section.Tables.Add(3, 3); // 3x3 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++)
{
table.Rows[i].Cells[j].Paragraphs.Add().AppendText($"Cell {i+1},{j+1}");
}
}
document.SaveAs("example_with_table.docx");
}
}
Imports IronWord
Friend Class Program
Shared Sub Main()
Dim document = New WordDocument()
Dim section = document.Sections.Add()
Dim table = section.Tables.Add(3, 3) ' 3x3 table
' Iterate over cells and set their content
For i As Integer = 0 To table.Rows.Count - 1
Dim j As Integer = 0
Do While j < table.Rows(i).Cells.Count
table.Rows(i).Cells(j).Paragraphs.Add().AppendText($"Cell {i+1},{j+1}")
j += 1
Loop
Next i
document.SaveAs("example_with_table.docx")
End Sub
End Class
Licencjonowanie i wsparcie dostępne
IronWord jest płatną biblioteką; jednakże, bezpłatne licencje próbne są dostępne tutaj.
Aby uzyskać więcej informacji o Iron Software, odwiedź naszą stronę internetową: https://ironsoftware.com/. Aby uzyskać więcej wsparcia i zapytań, proszę skontaktować się z naszym zespołem.
Wsparcie od Iron Software
W przypadku ogólnego wsparcia i pytań technicznych, prosimy o kontakt mailowy na adres: support@ironsoftware.com

