Skip to content

Commit

Permalink
Create Io.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuyafujisaki committed Jul 1, 2017
1 parent 1c09746 commit 904c856
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
9 changes: 5 additions & 4 deletions OpenXmlWordHelper/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,13 @@ static void DeletePart<T>(WorksheetPart wp) where T : OpenXmlPart
}

// Colunn index is zero-based.
public static void SetColumnJustification(MainDocumentPart mdp, int columnIndex, JustificationValues jv)
public static void SetColumnJustification(Table table, int columnIndex, JustificationValues jv)
{
foreach (var tr in mdp.Document.Body.GetFirstChild<Table>().Elements<TableRow>())
foreach (var tr in table.Elements<TableRow>())
{
// If columnIndex = 0, "tr.Elements<TableCell>().ToList()[columnIndex]" can be simplified to "tr.GetFirstChild<TableCell>()".
var p = tr.Elements<TableCell>().ToList()[columnIndex].GetFirstChild<Paragraph>();
var tc = columnIndex == 0 ? tr.GetFirstChild<TableCell>() : tr.Elements<TableCell>().ToList()[columnIndex];

var p = tc.GetFirstChild<Paragraph>();

if (p.ParagraphProperties == null)
{
Expand Down
10 changes: 10 additions & 0 deletions Test1/Io.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.IO;

namespace Test1
{
static class Io
{
internal static string Desktopize(params string[] paths) => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), Path.Combine(paths));
}
}
1 change: 1 addition & 0 deletions Test1/Test1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Io.cs" />
<Compile Include="UnitTest1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
18 changes: 8 additions & 10 deletions Test1/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
using OpenXmlWordHelper;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;

namespace Test1
{
[SuppressMessage("ReSharper", "PossiblyMistakenUseOfParamsMethod")]
[TestClass]
public class UnitTest1
{
Expand Down Expand Up @@ -88,8 +86,8 @@ public void TestCreateNumberingParagraphs()
[TestMethod]
public void TestMergeDocuments()
{
const string path1 = "Source1.docx";
const string path2 = "Source2.docx";
var path1 = Io.Desktopize("Source1.docx");
var path2 = Io.Desktopize("Source2.docx");

Api.MergeDocuments(path1, path2);

Expand All @@ -99,9 +97,9 @@ public void TestMergeDocuments()
[TestMethod]
public void TestMergeDocumentsToNewFile()
{
const string path1 = "Source1.docx";
const string path2 = "Source2.docx";
const string path3 = "Destination.docx";
var path1 = Io.Desktopize("Source1.docx");
var path2 = Io.Desktopize("Source2.docx");
var path3 = Io.Desktopize("Destination.docx");

Api.MergeDocuments(path1, path2, path3);

Expand All @@ -111,7 +109,7 @@ public void TestMergeDocumentsToNewFile()
[TestMethod]
public void TestProtectWord()
{
const string path = @"Sample.docx";
var path = Io.Desktopize("Sample.docx");

Api.ProtectWord(path, "dummy");

Expand All @@ -121,9 +119,9 @@ public void TestProtectWord()
[TestMethod]
public void TestSetColumnJustification()
{
const string path = @"Sample.docx";
var path = Io.Desktopize("Sample.docx");

TestRunner(path, mdp => Api.SetColumnJustification(mdp, 2, JustificationValues.Right));
TestRunner(path, mdp => Api.SetColumnJustification(mdp.Document.Body.GetFirstChild<Table>(), 0, JustificationValues.Center));
}
}
}

0 comments on commit 904c856

Please sign in to comment.