Twórz PDF dokumenty lub Word w C#

Utwórz programowo nowy dokument w prawie dowolnym formacie, korzystając z naszej C# biblioteki o wysokiej wierności

Korzystając z naszego programowania API, programiści .NET mogą z łatwością tworzyć dokumenty w PDF formatach, DOC, DOCX, HTML, EPUB i wielu innych za pomocą zaledwie kilku linijek kodu.

Zobacz fragment kodu

Utwórz dokument za pomocą C#

Dzięki podanemu potężnemu interfejsowi API programiści C# mogą tworzyć dokumenty w prawie każdym formacie. Aby to zrobić, musisz wykonać kilka kroków, korzystając z naszej biblioteki .NET:

  1. Dodaj nazwę pliku
  2. Zacznij tworzyć dokument za pomocą C#
  3. Zapisz utworzony dokument w wybranym formacie

Warto zauważyć, że pusty dokument technicznie powinien zawierać jeden akapit, więc gdy programowo utworzysz dokument, otrzymasz dokładnie taką podstawową strukturę dokumentu.

Pamiętaj, że możesz natychmiast dodać zawartość do nowo utworzonego dokumentu. W ten sposób otrzymasz nie tylko pusty dokument, ale dokument zawierający niezbędną treść. Aby uzyskać więcej informacji na temat edycji dokumentu, zobacz stronę Edycja.

Programowe tworzenie dokumentu w C#

Podana .NET biblioteka pozwala programowo stworzyć dokument w dowolnym obsługiwanym formacie – PDF, DOCX, DOC, RTF, ODT, EPUB, HTML i inne.

Wypróbuj naszą zaawansowaną funkcjonalność i zobacz, jak utworzyć dokument w niektórych formatach, korzystając z następującego przykładu:

Utwórz nowy dokument za pomocą C#
Wybierz format docelowy z listy
Uruchom kod
using Aspose.Words;

var doc = new Document();
var builder = new DocumentBuilder(doc);

var font = builder.Font;
font.Name = "Courier New";            
font.Color = Color.Blue;
font.Size = 36;
font.HighlightColor = Color.Yellow;

builder.Write("Morbi enim nunc faucibus a.");

doc.Save("Output.docx");
using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); doc.Save("Output.docx"); using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); var saveOptions = new PdfSaveOptions(); saveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Aspose bookmark", 1); doc.Save("Output.docx", saveOptions);
using Aspose.Words;

var doc = new Document();

var run = new Run(doc, "Proin eros metus, sagittis sed.");
var para = doc.FirstSection.Body.FirstParagraph;
para.AppendChild(run);

var comment = new Comment(doc)
{
    Author = "John Doe",
    Initial = "JD",
    DateTime = DateTime.Now
};
comment.SetText("Quisque fringilla leo.");            

var commentRangeStart = new CommentRangeStart(doc, comment.Id);
var commentRangeEnd = new CommentRangeEnd(doc, comment.Id);

run.ParentNode.InsertBefore(commentRangeStart, run);
run.ParentNode.InsertAfter(commentRangeEnd, run);
commentRangeEnd.ParentNode.InsertAfter(comment, commentRangeEnd);

comment.AddReply("Jane Doe", "JD", DateTime.Now, "Pellentesque vel sapien justo.");

doc.Save("Output.docx");
using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); doc.Save("Output.docx"); using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); var saveOptions = new PdfSaveOptions(); saveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Aspose bookmark", 1); doc.Save("Output.docx", saveOptions);
using Aspose.Words;

var doc = new Document();
var builder = new DocumentBuilder(doc);

var firstRun = new Run(doc, "Proin eros metus, sagittis sed. ");
var secondRun = new Run(doc, "Morbi enim nunc faucibus a.");
doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun);
doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun);

builder.MoveTo(secondRun);
builder.StartBookmark("Aspose bookmark");
// Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie.
if (secondRun.NextSibling != null)            
    builder.MoveTo(secondRun.NextSibling);            
else            
    builder.MoveTo(secondRun.ParentParagraph);            
builder.EndBookmark("Aspose bookmark");

doc.Save("Output.docx");
using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); doc.Save("Output.docx"); using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); var saveOptions = new PdfSaveOptions(); saveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Aspose bookmark", 1); doc.Save("Output.docx", saveOptions);
using Aspose.Words;

var doc = new Document();
var builder = new DocumentBuilder(doc);

Shape shape = builder.InsertChart(ChartType.Pie, 432, 252);
Chart chart = shape.Chart;
chart.Title.Text = "Demo Chart";

chart.Series.Clear();
chart.Series.Add("Series 1",
    new string[] { "Category1", "Category2", "Category3" },
    new double[] { 2.7, 3.2, 0.8 });

doc.Save("Output.docx");
using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); doc.Save("Output.docx"); using Aspose.Words; var doc = new Document(); var builder = new DocumentBuilder(doc); var firstRun = new Run(doc, "Proin eros metus, sagittis sed. "); var secondRun = new Run(doc, "Morbi enim nunc faucibus a."); doc.FirstSection.Body.FirstParagraph.AppendChild(firstRun); doc.FirstSection.Body.FirstParagraph.AppendChild(secondRun); builder.MoveTo(secondRun); builder.StartBookmark("Aspose bookmark"); // Jeśli NextSibling ma wartość null, najprawdopodobniej jest to ostatnie Run w akapicie. if (secondRun.NextSibling != null) builder.MoveTo(secondRun.NextSibling); else builder.MoveTo(secondRun.ParentParagraph); builder.EndBookmark("Aspose bookmark"); var saveOptions = new PdfSaveOptions(); saveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Aspose bookmark", 1); doc.Save("Output.docx", saveOptions);
Uruchom kod

Jak zrobić dokument w C#

  1. Zainstaluj Aspose.Words for .NET
  2. Dodaj odniesienie do biblioteki (zaimportuj bibliotekę) do swojego C# projektu
  3. Utwórz nowy dokument
  4. Wywołaj metodę "Save()", przekazując nazwę pliku
  5. Uzyskaj wynik jako osobny plik

C# biblioteka do tworzenia dokumentów

Istnieją trzy alternatywne opcje instalacji "Aspose.Words for .NET" w systemie. Wybierz taki, który odpowiada Twoim potrzebom i postępuj zgodnie z instrukcjami krok po kroku:

wymagania systemowe

Nasz produkt jest w pełni wieloplatformowy i obsługuje wszystkie główne implementacje .NET:

  • .NET ≥ 5.0
  • .NET Core ≥ 2.0
  • .NET Standard ≥ 2.0
  • .NET Framework ≥ 3.5
  • MonoMac
  • MonoAndroid
  • Xamarin

O ile kod .NET nie jest zależny od sprzętu lub systemu operacyjnego, ale tylko od maszyny wirtualnej, możesz swobodnie tworzyć dowolne oprogramowanie dla systemów Windows, macOS, Android, iOS i Linux. Upewnij się tylko, że masz zainstalowaną odpowiednią wersję .NET Framework, .NET Core, Windows Azure, Mono lub Xamarin.

Do tworzenia aplikacji C#, F#, VB.NET zalecamy używanie zintegrowanych środowisk programistycznych Microsoft Visual Studio, Xamarin i MonoDevelop.

Aby uzyskać więcej informacji, zapoznaj się z dokumentacją produktu.

Najpopularniejsze formaty plików

5%

Subskrybuj aktualizacje produktów Aspose

Otrzymuj comiesięczne biuletyny i oferty dostarczane bezpośrednio do Twojej skrzynki pocztowej.

© Aspose Pty Ltd 2001-2024. Wszelkie prawa zastrzeżone.