Skip to content

Commit

Permalink
Merge pull request #10 from Backs/empty_theme
Browse files Browse the repository at this point in the history
parse template with empty theme
  • Loading branch information
aldobrynin authored Jul 27, 2022
2 parents 5602541 + 6d9022d commit ead6349
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
Binary file not shown.
24 changes: 24 additions & 0 deletions Excel.TemplateEngine.Tests/FileGeneratingTests/TemplateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.IO;

using NUnit.Framework;

using SkbKontur.Excel.TemplateEngine.FileGenerating;

using Vostok.Logging.Console;

namespace SkbKontur.Excel.TemplateEngine.Tests.FileGeneratingTests
{
[TestFixture]
public class TemplateTests : FileBasedTestBase
{
[Test]
public void TemplateWithoutThemeTest()
{
var content = File.ReadAllBytes(GetFilePath("template_2.xlsx"));
using (var template = ExcelDocumentFactory.TryCreateFromTemplate(content, new ConsoleLog()))
{
Assert.IsNotNull(template);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Xml;

using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;

Expand All @@ -31,13 +32,26 @@ public ExcelDocument([NotNull] byte[] template, [NotNull] ILog logger)
documentMemoryStream.Write(template, 0, template.Length);
spreadsheetDocument = SpreadsheetDocument.Open(documentMemoryStream, true);

documentStyle = new ExcelDocumentStyle(spreadsheetDocument.GetOrCreateSpreadsheetStyles(), spreadsheetDocument.WorkbookPart.ThemePart.Theme, this.logger);
var theme = GetEmptyTheme();
documentStyle = new ExcelDocumentStyle(spreadsheetDocument.GetOrCreateSpreadsheetStyles(), spreadsheetDocument.WorkbookPart?.ThemePart?.Theme ?? theme, this.logger);
excelSharedStrings = new ExcelSharedStrings(spreadsheetDocument.GetOrCreateSpreadsheetSharedStrings());
spreadsheetDisposed = false;

SetDefaultCreatorAndEditor();
}

private static Theme GetEmptyTheme()
{
var theme = new Theme
{
ThemeElements = new ThemeElements
{
ColorScheme = new ColorScheme()
}
};
return theme;
}

private void ThrowIfSpreadsheetDisposed()
{
if (spreadsheetDisposed)
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1",
"version": "1.2",
"assemblyVersion": {
"precision": "build"
},
Expand Down

0 comments on commit ead6349

Please sign in to comment.