-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f77afad
commit 1ff961a
Showing
7 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,4 +362,6 @@ MigrationBackup/ | |
# Fody - auto-generated XML schema | ||
FodyWeavers.xsd | ||
|
||
.vscode/* | ||
.vscode/* | ||
|
||
build/* |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
This is a small project (under development) that allows to create Microsoft Word documents (.docx) using .NET. | ||
Underneath it uses [OpenXML SDK](https://github.com/OfficeDev/Open-XML-SDK) but heavily simplifies it. | ||
It was created because working with OpenXML is way too hard for me, and time consuming. | ||
I originally created it for using within PowerShell module called [PSWriteOffice](https://github.com/EvotecIT/PSWriteOffice), | ||
but thought it may be useful for others to use in the .NET community. | ||
|
||
## Examples | ||
|
||
### Basic Document with few document properties and paragraph | ||
|
||
This short example show how to create Word Document with just one paragraph with Text and few document properties. | ||
|
||
```csharp | ||
string filePath = @"C:\Support\GitHub\PSWriteOffice\Examples\Documents\BasicDocument.docx"; | ||
|
||
using (WordDocument document = WordDocument.Create(filePath)) { | ||
document.Title = "This is my title"; | ||
document.Creator = "Przemysław Kłys"; | ||
document.Keywords = "word, docx, test"; | ||
|
||
var paragraph = document.AddParagraph("Basic paragraph"); | ||
paragraph.ParagraphAlignment = JustificationValues.Center; | ||
paragraph.Color = SixLabors.ImageSharp.Color.Red.ToHexColor(); | ||
|
||
document.Save(true); | ||
} | ||
``` | ||
|
||
### Basic Document with Headers/Footers (first, odd, even) | ||
|
||
This short example shows how to add headers and footers to Word Document. | ||
|
||
```csharp | ||
using (WordDocument document = WordDocument.Create(filePath)) { | ||
document.Sections[0].PageOrientation = PageOrientationValues.Landscape; | ||
document.AddParagraph("Test Section0"); | ||
document.AddHeadersAndFooters(); | ||
document.DifferentFirstPage = true; | ||
document.DifferentOddAndEvenPages = true; | ||
|
||
document.Sections[0].Header.First.AddParagraph().SetText("Test Section 0 - First Header"); | ||
document.Sections[0].Header.Default.AddParagraph().SetText("Test Section 0 - Header"); | ||
document.Sections[0].Header.Even.AddParagraph().SetText("Test Section 0 - Even"); | ||
|
||
document.AddPageBreak(); | ||
document.AddPageBreak(); | ||
document.AddPageBreak(); | ||
document.AddPageBreak(); | ||
|
||
var section1 = document.AddSection(); | ||
section1.PageOrientation = PageOrientationValues.Portrait; | ||
section1.AddParagraph("Test Section1"); | ||
section1.AddHeadersAndFooters(); | ||
section1.Header.Default.AddParagraph().SetText("Test Section 1 - Header"); | ||
section1.DifferentFirstPage = true; | ||
section1.Header.First.AddParagraph().SetText("Test Section 1 - First Header"); | ||
|
||
document.AddPageBreak(); | ||
document.AddPageBreak(); | ||
document.AddPageBreak(); | ||
document.AddPageBreak(); | ||
|
||
var section2 = document.AddSection(); | ||
section2.AddParagraph("Test Section2"); | ||
section2.PageOrientation = PageOrientationValues.Landscape; | ||
section2.AddHeadersAndFooters(); | ||
section2.Header.Default.AddParagraph().SetText("Test Section 2 - Header"); | ||
|
||
document.AddParagraph("Test Section2 - Paragraph 1"); | ||
|
||
var section3 = document.AddSection(); | ||
section3.AddParagraph("Test Section3"); | ||
section3.AddHeadersAndFooters(); | ||
section3.Header.Default.AddParagraph().SetText("Test Section 3 - Header"); | ||
|
||
Console.WriteLine("Section 0 - Text 0: " + document.Sections[0].Paragraphs[0].Text); | ||
Console.WriteLine("Section 1 - Text 0: " + document.Sections[1].Paragraphs[0].Text); | ||
Console.WriteLine("Section 2 - Text 0: " + document.Sections[2].Paragraphs[0].Text); | ||
Console.WriteLine("Section 2 - Text 1: " + document.Sections[2].Paragraphs[1].Text); | ||
Console.WriteLine("Section 3 - Text 0: " + document.Sections[3].Paragraphs[0].Text); | ||
|
||
Console.WriteLine("Section 0 - Text 0: " + document.Sections[0].Header.Default.Paragraphs[0].Text); | ||
Console.WriteLine("Section 1 - Text 0: " + document.Sections[1].Header.Default.Paragraphs[0].Text); | ||
Console.WriteLine("Section 2 - Text 0: " + document.Sections[2].Header.Default.Paragraphs[0].Text); | ||
Console.WriteLine("Section 3 - Text 0: " + document.Sections[3].Header.Default.Paragraphs[0].Text); | ||
document.Save(true); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters