diff --git a/.gitignore b/.gitignore index e5b0f610..22e45a05 100644 --- a/.gitignore +++ b/.gitignore @@ -362,4 +362,6 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd -.vscode/* \ No newline at end of file +.vscode/* + +build/* \ No newline at end of file diff --git a/Assets/OfficeIMO.ico b/Assets/OfficeIMO.ico new file mode 100644 index 00000000..7a87d804 Binary files /dev/null and b/Assets/OfficeIMO.ico differ diff --git a/Assets/README.MD b/Assets/README.MD new file mode 100644 index 00000000..f20f196b --- /dev/null +++ b/Assets/README.MD @@ -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); +} +``` \ No newline at end of file diff --git a/OfficeIMO.Examples/OfficeIMO.Examples.csproj b/OfficeIMO.Examples/OfficeIMO.Examples.csproj index 7f49ea48..5e4f35b7 100644 --- a/OfficeIMO.Examples/OfficeIMO.Examples.csproj +++ b/OfficeIMO.Examples/OfficeIMO.Examples.csproj @@ -71,8 +71,4 @@ - - - - diff --git a/OfficeIMO.Excel/OfficeIMO.Excel.csproj b/OfficeIMO.Excel/OfficeIMO.Excel.csproj index affc2cc8..9446a9f6 100644 --- a/OfficeIMO.Excel/OfficeIMO.Excel.csproj +++ b/OfficeIMO.Excel/OfficeIMO.Excel.csproj @@ -48,7 +48,6 @@ - diff --git a/OfficeIMO.Tests/OfficeIMO.Tests.csproj b/OfficeIMO.Tests/OfficeIMO.Tests.csproj index 7963be8f..96f0a887 100644 --- a/OfficeIMO.Tests/OfficeIMO.Tests.csproj +++ b/OfficeIMO.Tests/OfficeIMO.Tests.csproj @@ -7,7 +7,6 @@ - diff --git a/OfficeIMO.Word/OfficeIMO.Word.csproj b/OfficeIMO.Word/OfficeIMO.Word.csproj index 79b5647c..7e7a69fc 100644 --- a/OfficeIMO.Word/OfficeIMO.Word.csproj +++ b/OfficeIMO.Word/OfficeIMO.Word.csproj @@ -5,7 +5,7 @@ OfficeIMO.Word OfficeIMO.Word - 0.1.3 + 0.1.4 netstandard2.0;netstandard2.1;net472;net48;net5.0;net6.0 True Evotec @@ -28,6 +28,8 @@ --> False OfficeIMO.ico + README.MD + git @@ -62,6 +64,10 @@ True \ + + True + \ + True \ @@ -70,7 +76,6 @@ -