Make Word using .NET library

Our powerful C# library allows developers to programmatically create Word in just a few steps

.NET developers can easily make Word using only our powerful product API. It means that our solution will provide programmers with everything they need to create Word in C#.

View code snippet

Make Word in C# programmatically

With our C# library developers can easily make Word from scratch. To do this, .NET developers need to perform just a few steps:

  1. Add file name
  2. Start creating a Word document using C#
  3. Save the output Word file

It is worth noting that a blank document is technically supposed to contain one paragraph, so when you programmatically create a Word document, you will get exactly that basic document structure.

Note that you can instantly add content to a newly created Word file. Thus, you will get not just an empty document, but a document containing the necessary content. For more information on how to edit a document, see the Editing page.

Create Word in C#

This .NET library allows you to programmatically create Word documents. Try our powerful functionality and see how to create Word using the following example:

Make a new DOCX using C#
Select the target format from the list
Run code
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"); // If NextSibling is null, then most likely this is the last Run in the Paragraph. 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"); // If NextSibling is null, then most likely this is the last Run in the Paragraph. 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"); // If NextSibling is null, then most likely this is the last Run in the Paragraph. 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"); // If NextSibling is null, then most likely this is the last Run in the Paragraph. 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");
// If NextSibling is null, then most likely this is the last Run in the Paragraph.
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"); // If NextSibling is null, then most likely this is the last Run in the Paragraph. 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"); // If NextSibling is null, then most likely this is the last Run in the Paragraph. 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"); // If NextSibling is null, then most likely this is the last Run in the Paragraph. 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"); // If NextSibling is null, then most likely this is the last Run in the Paragraph. 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);
Run code

How to make Word in C#

  1. Install Aspose.Words for .NET
  2. Add a library reference (import the library) to your C# project
  3. Create a new Word document
  4. Call the Save() method, passing the file name
  5. Get the result as a separate file

C# library to create Word

There are three alternative options to install "Aspose.Words for .NET" onto your system. Please choose one that resembles your needs and follow the step-by-step instructions:

System Requirements

Our product is fully cross-platform and supports all major .NET implementations:

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

As far as .NET code doesn't depend on the underlying hardware or operating system, but only on a Virtual Machine, you are free to develop any kind of software for Windows, macOS, Android, iOS and Linux. Just make sure you have installed the corresponding version of .NET Framework, .NET Core, Windows Azure, Mono or Xamarin.

We recommend using Microsoft Visual Studio, Xamarin, and MonoDevelop integrated development environments to create C#, F#, VB.NET applications.

Fore more details please refer to Product Documentation.

Other supported file formats

You can create documents in other file formats:

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2024. All Rights Reserved.