Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
PrzemyslawKlys committed Apr 3, 2022
1 parent f77afad commit 1ff961a
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,6 @@ MigrationBackup/
# Fody - auto-generated XML schema
FodyWeavers.xsd

.vscode/*
.vscode/*

build/*
Binary file added Assets/OfficeIMO.ico
Binary file not shown.
88 changes: 88 additions & 0 deletions Assets/README.MD
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);
}
```
4 changes: 0 additions & 4 deletions OfficeIMO.Examples/OfficeIMO.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,4 @@
<Folder Include="Word\Sections\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DependencyValidation.Analyzers" Version="0.11.0" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion OfficeIMO.Excel/OfficeIMO.Excel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.16.0" />
<PackageReference Include="Microsoft.DependencyValidation.Analyzers" Version="0.11.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.0" />
</ItemGroup>

Expand Down
1 change: 0 additions & 1 deletion OfficeIMO.Tests/OfficeIMO.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.17.0" />
<PackageReference Include="Microsoft.DependencyValidation.Analyzers" Version="0.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="SemanticComparison" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down
9 changes: 7 additions & 2 deletions OfficeIMO.Word/OfficeIMO.Word.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>OfficeIMO.Word</AssemblyName>
<AssemblyTitle>OfficeIMO.Word</AssemblyTitle>

<VersionPrefix>0.1.3</VersionPrefix>
<VersionPrefix>0.1.4</VersionPrefix>
<TargetFrameworks>netstandard2.0;netstandard2.1;net472;net48;net5.0;net6.0</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Company>Evotec</Company>
Expand All @@ -28,6 +28,8 @@
-->
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<ApplicationIcon>OfficeIMO.ico</ApplicationIcon>
<PackageReadmeFile>README.MD</PackageReadmeFile>
<RepositoryType>git</RepositoryType>
</PropertyGroup>

<Choose>
Expand Down Expand Up @@ -62,6 +64,10 @@
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\Assets\README.MD">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
Expand All @@ -70,7 +76,6 @@

<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.16.0" />
<PackageReference Include="Microsoft.DependencyValidation.Analyzers" Version="0.11.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.0" />
</ItemGroup>

Expand Down

0 comments on commit 1ff961a

Please sign in to comment.