https://github.com/nickelony/quickword.openxml
An open-source set of extension methods for DocumentFormat.OpenXml which simplifies creating and modifying Word documents (such as .docx).
https://github.com/nickelony/quickword.openxml
dotnet office openxml word
Last synced: 12 months ago
JSON representation
An open-source set of extension methods for DocumentFormat.OpenXml which simplifies creating and modifying Word documents (such as .docx).
- Host: GitHub
- URL: https://github.com/nickelony/quickword.openxml
- Owner: Nickelony
- License: mit
- Created: 2023-09-26T09:39:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-12T22:19:06.000Z (over 2 years ago)
- Last Synced: 2025-02-14T05:35:18.266Z (about 1 year ago)
- Topics: dotnet, office, openxml, word
- Language: C#
- Homepage: https://www.nuget.org/packages/QuickWord.OpenXml
- Size: 200 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#  QuickWord for DocumentFormat.OpenXml
An open-source set of extension methods for `DocumentFormat.OpenXml` which simplifies creating and modifying Word documents (such as .docx).
You can use these methods with your existing `DocumentFormat.OpenXml` code without having to change anything.
If you think something very important is missing in this library, please create an [Issue](https://github.com/Nickelony/QuickWord.OpenXml/issues) for it. I'm willing to implement anything that is crucial.
Contributions via **Pull Requests** are always welcome! :)
If you have any questions, feel free to open a [Discussion](https://github.com/Nickelony/QuickWord.OpenXml/discussions).
Please remember that I may not always be able to push updates because of lack of time. If you wish to support me, you can buy me a coffee:
Thank you! ❤️
# Getting Started
Example document creation with 1 formatted paragraph:
```cs
string fileName = "TEST.docx";
using (var document = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))
{
Body body = document.CreateBody()
.PageWidth(21, MeasuringUnits.Centimeters) // A4 width
.PageHeight(29.7, MeasuringUnits.Centimeters); // A4 height
body.AppendChild(new Paragraph(
new Run().Text("This is a single, centered paragraph.")
.FontSize(16)
.FontColor("Red") // #FF0000 will also work
.FontFace("Times New Roman"))
.Justification(JustificationValues.Center));
document.Save();
}
```
# Highlighted Features
- Super quick and easy Builder-like pattern:
```cs
var run = new Run().Text("This is a simple Run.")
.FontSize(24)
.FontColor("Red")
.Bold()
.Italic();
```
---
- The ability to create Paragraphs with multiple Runs and multiple formattings:
```cs
Run[] runs = new[]
{
new Run().Text("This is a").FontSize(16),
new Run().Text(" single paragraph ").FontFace("Comic Sans MS"),
new Run().Text("with 3 Runs.").HighlightColor(HighlightColorValues.Cyan)
};
body.AppendChild(new Paragraph(runs))
```
Example with 5 runs:

---
- The ability to create tables quickly:
```cs
body.AppendChild(QTable.Create(new[]
{
new[] { "1", "John", "Doe" },
new[] { "2", "Jane", "Doe" },
new[] { "3", "John", "Smith" },
new[] { "4", "Jane", "Smith" }
}));
```
Example:

---
- The ability quickly merge cells:
```cs
// Merge cells [0,0] and [1,0] (vertically)
table.Rows(0)?.Cells(0)?.VerticalMerge(MergedCellValues.Restart);
table.Rows(1)?.Cells(0)?.VerticalMerge(MergedCellValues.Continue);
// Merge cells [2,0] and [3,0] (vertically)
table.Rows(2)?.Cells(0)?.VerticalMerge(MergedCellValues.Restart);
table.Rows(3)?.Cells(0)?.VerticalMerge(MergedCellValues.Continue);
```
Example:

---
- The ability to quickly create formatted rows and cells:
```cs
table1.AppendChild(QTableRow.Create(
new[] { "ID", "First Name", "Last Name" },
rowFormatting: new TableRowFormatting { IsHeader = true },
runFormatting: new RunFormatting { Bold = true }));
```
- The ability to easily customize existing table cells:
```cs
foreach (TableCell? cell in table2.GetColumnOfCells(3).Skip(1)) // 4th column of cells, skip header cell
{
if (cell?.Paragraphs(0)?.GetText() == "Yes")
cell?.FillColor("LightGreen");
else
cell?.FillColor("LightPink");
}
```
Example:

---
- The ability to create inlined images:
```cs
body.AppendChild(new Paragraph(
new Run(QDrawing.FromImage(body, "Icon.png", ImagePartType.Png, 32, 32)),
new Run().Text(" This image is inlined with the text.").VerticalPosition(8)
).Justification(JustificationValues.Center));
```
Example:

---
- The ability to create anchored images:
```cs
body.AppendChild(new Paragraph(
new Run(QDrawing.FromImage(body, "Icon.png", ImagePartType.Png, 128, 128)
.ToAnchoredDrawing()
.AbsoluteVerticalPosition(0, ImageMeasuringUnits.Pixels, DW.VerticalRelativePositionValues.Paragraph)
.SquareWrapping(0, 0, 0.5, 0, ImageMeasuringUnits.Centimeters)),
new Run().Text("This\nimage\nis\naligned\nbefore\nthe text.\n")
));
```
Example:

With images you can also:
- Set the transparency
- Set the rotation
- Set cropping
- Set a border
- Set text wrapping
- Set the position
- many more...

---
- You can also use additional `Paragraph` inherited objects, such as:
- `EmptyLine`
- `PageBreak`
- `HorizontalLine`