mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-06-15 13:25:08 -04:00
Improves "save as Excel" functionality (#2266)
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<numFmt numFmtId="168" formatCode="yyyy-mm-dd hh:mm:ss" />
|
||||
<numFmt numFmtId="169" formatCode="[h]:mm:ss" />
|
||||
</numFmts>
|
||||
<fonts count="1">
|
||||
<fonts count="2">
|
||||
<font>
|
||||
<sz val="11" />
|
||||
<color theme="1" />
|
||||
@@ -14,6 +14,14 @@
|
||||
<family val="2" />
|
||||
<scheme val="minor" />
|
||||
</font>
|
||||
<font>
|
||||
<b />
|
||||
<sz val="11" />
|
||||
<color theme="1" />
|
||||
<name val="Calibri" />
|
||||
<family val="2" />
|
||||
<scheme val="minor" />
|
||||
</font>
|
||||
</fonts>
|
||||
<fills count="1">
|
||||
<fill>
|
||||
@@ -32,12 +40,13 @@
|
||||
<cellStyleXfs count="1">
|
||||
<xf numFmtId="0" fontId="0" fillId="0" borderId="0" />
|
||||
</cellStyleXfs>
|
||||
<cellXfs count="5">
|
||||
<cellXfs count="6">
|
||||
<xf xfId="0" />
|
||||
<xf numFmtId="166" xfId="0" applyNumberFormat="1" />
|
||||
<xf numFmtId="167" xfId="0" applyNumberFormat="1" />
|
||||
<xf numFmtId="168" xfId="0" applyNumberFormat="1" />
|
||||
<xf numFmtId="169" xfId="0" applyNumberFormat="1" />
|
||||
<xf xfId="0" fontId="1" />
|
||||
</cellXfs>
|
||||
<cellStyles count="1">
|
||||
<cellStyle name="Normal" builtinId="0" xfId="0" />
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<sheetData>
|
||||
<row r="1">
|
||||
<c r="B1" t="inlineStr"><is><t></t></is></c>
|
||||
<c r="C1" t="inlineStr"><is><t>test string</t></is></c>
|
||||
<c r="D1"><v>3</v></c>
|
||||
<c r="E1"><v>3.5</v></c>
|
||||
<c r="F1" t="b"><v>0</v></c>
|
||||
<c r="G1" t="b"><v>1</v></c>
|
||||
</row>
|
||||
<row r="2">
|
||||
<c r="A2" t="inlineStr"><is><t>1900-02-28</t></is></c>
|
||||
<c r="B2" s="1"><v>61</v></c>
|
||||
<c r="C2" s="3"><v>61.625</v></c>
|
||||
<c r="D2" s="2"><v>0.625</v></c>
|
||||
<c r="E2" s="2"><v>0.625</v></c>
|
||||
<c r="F2" s="4"><v>1</v></c>
|
||||
</row>
|
||||
</sheetData>
|
||||
<autoFilter ref="A1:G1" />
|
||||
</worksheet>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<sheetData>
|
||||
<row r="1">
|
||||
<c r="B1" t="inlineStr"><is><t></t></is></c>
|
||||
<c r="C1" t="inlineStr"><is><t>test string</t></is></c>
|
||||
<c r="D1"><v>3</v></c>
|
||||
<c r="E1"><v>3.5</v></c>
|
||||
<c r="F1" t="b"><v>0</v></c>
|
||||
<c r="G1" t="b"><v>1</v></c>
|
||||
</row>
|
||||
<row r="2">
|
||||
<c r="A2" t="inlineStr"><is><t>1900-02-28</t></is></c>
|
||||
<c r="B2" s="1"><v>61</v></c>
|
||||
<c r="C2" s="3"><v>61.625</v></c>
|
||||
<c r="D2" s="2"><v>0.625</v></c>
|
||||
<c r="E2" s="2"><v>0.625</v></c>
|
||||
<c r="F2" s="4"><v>1</v></c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<sheetViews>
|
||||
<sheetView tabSelected="1" workbookViewId="0">
|
||||
<pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen" />
|
||||
<selection pane="bottomLeft" />
|
||||
</sheetView>
|
||||
</sheetViews>
|
||||
<sheetData>
|
||||
<row r="1">
|
||||
<c r="B1" t="inlineStr"><is><t></t></is></c>
|
||||
<c r="C1" t="inlineStr"><is><t>test string</t></is></c>
|
||||
<c r="D1"><v>3</v></c>
|
||||
<c r="E1"><v>3.5</v></c>
|
||||
<c r="F1" t="b"><v>0</v></c>
|
||||
<c r="G1" t="b"><v>1</v></c>
|
||||
</row>
|
||||
<row r="2">
|
||||
<c r="A2" t="inlineStr"><is><t>1900-02-28</t></is></c>
|
||||
<c r="B2" s="1"><v>61</v></c>
|
||||
<c r="C2" s="3"><v>61.625</v></c>
|
||||
<c r="D2" s="2"><v>0.625</v></c>
|
||||
<c r="E2" s="2"><v>0.625</v></c>
|
||||
<c r="F2" s="4"><v>1</v></c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<worksheet xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
|
||||
<cols>
|
||||
<col min="1" max="1" width="2.28515625" bestFit="1" customWidth="1" />
|
||||
<col min="2" max="2" width="2.42578125" bestFit="1" customWidth="1" />
|
||||
<col min="3" max="3" width="2.5703125" bestFit="1" customWidth="1" />
|
||||
<col min="4" max="4" width="2.7109375" bestFit="1" customWidth="1" />
|
||||
<col min="5" max="5" width="2.85546875" bestFit="1" customWidth="1" />
|
||||
<col min="6" max="6" width="3" bestFit="1" customWidth="1" />
|
||||
<col min="7" max="7" width="3.140625" bestFit="1" customWidth="1" />
|
||||
</cols>
|
||||
<sheetData>
|
||||
<row r="1">
|
||||
<c r="B1" t="inlineStr"><is><t></t></is></c>
|
||||
<c r="C1" t="inlineStr"><is><t>test string</t></is></c>
|
||||
<c r="D1"><v>3</v></c>
|
||||
<c r="E1"><v>3.5</v></c>
|
||||
<c r="F1" t="b"><v>0</v></c>
|
||||
<c r="G1" t="b"><v>1</v></c>
|
||||
</row>
|
||||
<row r="2">
|
||||
<c r="A2" t="inlineStr"><is><t>1900-02-28</t></is></c>
|
||||
<c r="B2" s="1"><v>61</v></c>
|
||||
<c r="C2" s="3"><v>61.625</v></c>
|
||||
<c r="D2" s="2"><v>0.625</v></c>
|
||||
<c r="E2" s="2"><v>0.625</v></c>
|
||||
<c r="F2" s="4"><v>1</v></c>
|
||||
</row>
|
||||
</sheetData>
|
||||
</worksheet>
|
||||
@@ -16,14 +16,14 @@ using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
{
|
||||
public partial class SaveAsExcelFileStreamWriterHelperTests : IDisposable
|
||||
public partial class SaveAsExcelFileStreamWriterHelperTests
|
||||
{
|
||||
private Stream _stream;
|
||||
public SaveAsExcelFileStreamWriterHelperTests()
|
||||
[Test]
|
||||
public void DefaultSheet()
|
||||
{
|
||||
_stream = new MemoryStream();
|
||||
using (var helper = new SaveAsExcelFileStreamWriterHelper(_stream, true))
|
||||
using (var sheet = helper.AddSheet())
|
||||
var stream = new MemoryStream();
|
||||
using (var helper = new SaveAsExcelFileStreamWriterHelper(stream, true))
|
||||
using (var sheet = helper.AddSheet(null, 7))
|
||||
{
|
||||
var value = new DbCellValue();
|
||||
sheet.AddRow();
|
||||
@@ -70,64 +70,431 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
value.RawObject = new TimeSpan(24, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
}
|
||||
|
||||
ContentMatch(stream, "[Content_Types].xml");
|
||||
ContentMatch(stream, "_rels/.rels");
|
||||
ContentMatch(stream, "xl/_rels/workbook.xml.rels");
|
||||
ContentMatch(stream, "xl/styles.xml");
|
||||
ContentMatch(stream, "xl/workbook.xml");
|
||||
ContentMatch(stream, "xl/worksheets/sheet1.xml");
|
||||
|
||||
stream.Dispose();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void SheetWithFrozenHeaderRow()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
using (var helper = new SaveAsExcelFileStreamWriterHelper(stream, true))
|
||||
using (var sheet = helper.AddSheet(null, 7))
|
||||
{
|
||||
sheet.FreezeHeaderRow();
|
||||
|
||||
var value = new DbCellValue();
|
||||
sheet.AddRow();
|
||||
|
||||
value.IsNull = true;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.IsNull = false;
|
||||
value.RawObject = "";
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = "test string";
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = 3;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = 3.5;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = false;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = true;
|
||||
sheet.AddCell(value);
|
||||
|
||||
sheet.AddRow();
|
||||
|
||||
value.RawObject = new DateTime(1900, 2, 28);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1900, 3, 1);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1900, 3, 1, 15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1, 1, 1, 15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new TimeSpan(15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new TimeSpan(24, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
}
|
||||
|
||||
ContentMatch(stream, "[Content_Types].xml");
|
||||
ContentMatch(stream, "_rels/.rels");
|
||||
ContentMatch(stream, "xl/_rels/workbook.xml.rels");
|
||||
ContentMatch(stream, "xl/styles.xml");
|
||||
ContentMatch(stream, "xl/workbook.xml");
|
||||
ContentMatch(stream, "xl/worksheets/sheet1.xml", "xl/worksheets/sheet1-headerRowFrozen.xml");
|
||||
|
||||
stream.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SheetWithFrozenHeaderRowCalledTooLate()
|
||||
{
|
||||
var expectedException = new InvalidOperationException("Must be called before calling AddRow");
|
||||
var actualException = new Exception();
|
||||
var stream = new MemoryStream();
|
||||
using (var helper = new SaveAsExcelFileStreamWriterHelper(stream, true))
|
||||
using (var sheet = helper.AddSheet(null, 7))
|
||||
{
|
||||
sheet.AddRow();
|
||||
|
||||
try
|
||||
{
|
||||
sheet.FreezeHeaderRow();
|
||||
|
||||
Assert.Fail("Did not throw an exception when calling FreezeHeaderRow too late");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
actualException = e;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.AreEqual(expectedException.GetType(), actualException.GetType());
|
||||
Assert.AreEqual(expectedException.Message, actualException.Message);
|
||||
|
||||
stream.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SheetWithBoldHeaderRow()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
using (var helper = new SaveAsExcelFileStreamWriterHelper(stream, true))
|
||||
using (var sheet = helper.AddSheet(null, 7))
|
||||
{
|
||||
var value = new DbCellValue();
|
||||
sheet.AddRow();
|
||||
|
||||
value.IsNull = true;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.IsNull = false;
|
||||
value.RawObject = "";
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = "test string";
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = 3;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = 3.5;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = false;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = true;
|
||||
sheet.AddCell(value);
|
||||
|
||||
sheet.AddRow();
|
||||
|
||||
value.RawObject = new DateTime(1900, 2, 28);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1900, 3, 1);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1900, 3, 1, 15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1, 1, 1, 15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new TimeSpan(15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new TimeSpan(24, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
}
|
||||
|
||||
ContentMatch(stream, "[Content_Types].xml");
|
||||
ContentMatch(stream, "_rels/.rels");
|
||||
ContentMatch(stream, "xl/_rels/workbook.xml.rels");
|
||||
ContentMatch(stream, "xl/styles.xml");
|
||||
ContentMatch(stream, "xl/workbook.xml");
|
||||
ContentMatch(stream, "xl/worksheets/sheet1.xml", "xl/worksheets/sheet1-headerRowBold.xml");
|
||||
|
||||
stream.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SheetWithAutoFilterEnabled()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
using (var helper = new SaveAsExcelFileStreamWriterHelper(stream, true))
|
||||
using (var sheet = helper.AddSheet(null, 7))
|
||||
{
|
||||
sheet.EnableAutoFilter();
|
||||
|
||||
var value = new DbCellValue();
|
||||
sheet.AddRow();
|
||||
|
||||
value.IsNull = true;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.IsNull = false;
|
||||
value.RawObject = "";
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = "test string";
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = 3;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = 3.5;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = false;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = true;
|
||||
sheet.AddCell(value);
|
||||
|
||||
sheet.AddRow();
|
||||
|
||||
value.RawObject = new DateTime(1900, 2, 28);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1900, 3, 1);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1900, 3, 1, 15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1, 1, 1, 15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new TimeSpan(15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new TimeSpan(24, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
}
|
||||
|
||||
ContentMatch(stream, "[Content_Types].xml");
|
||||
ContentMatch(stream, "_rels/.rels");
|
||||
ContentMatch(stream, "xl/_rels/workbook.xml.rels");
|
||||
ContentMatch(stream, "xl/styles.xml");
|
||||
ContentMatch(stream, "xl/workbook.xml");
|
||||
ContentMatch(stream, "xl/worksheets/sheet1.xml", "xl/worksheets/sheet1-autoFilterEnabled.xml");
|
||||
|
||||
stream.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SheetWriteColumnInformationCalledTooLate()
|
||||
{
|
||||
var expectedException = new InvalidOperationException("Must be called before calling AddRow");
|
||||
var actualException = new Exception();
|
||||
var stream = new MemoryStream();
|
||||
using (var helper = new SaveAsExcelFileStreamWriterHelper(stream, true))
|
||||
using (var sheet = helper.AddSheet(null, 7))
|
||||
{
|
||||
sheet.AddRow();
|
||||
|
||||
try
|
||||
{
|
||||
sheet.WriteColumnInformation(new []{ 1F, 2F, 3F, 4F, 5F, 6F, 7F });
|
||||
|
||||
Assert.Fail("Did not throw an exception when calling WriteColumnInformation too late");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
actualException = e;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.AreEqual(expectedException.GetType(), actualException.GetType());
|
||||
Assert.AreEqual(expectedException.Message, actualException.Message);
|
||||
|
||||
stream.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SheetWriteColumnInformationWithWrongAmount()
|
||||
{
|
||||
var expectedException = new InvalidOperationException("Column count mismatch");
|
||||
var actualException = new Exception();
|
||||
var stream = new MemoryStream();
|
||||
using (var helper = new SaveAsExcelFileStreamWriterHelper(stream, true))
|
||||
using (var sheet = helper.AddSheet(null, 7))
|
||||
{
|
||||
try
|
||||
{
|
||||
sheet.WriteColumnInformation(new[] { 1F, 2F, 3F, 4F, 5F });
|
||||
|
||||
Assert.Fail("Did not throw an exception when calling WriteColumnInformation with the wrong number of columns");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
actualException = e;
|
||||
}
|
||||
|
||||
var value = new DbCellValue();
|
||||
sheet.AddRow();
|
||||
|
||||
value.IsNull = true;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.IsNull = false;
|
||||
value.RawObject = "";
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = "test string";
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = 3;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = 3.5;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = false;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = true;
|
||||
sheet.AddCell(value);
|
||||
|
||||
sheet.AddRow();
|
||||
|
||||
value.RawObject = new DateTime(1900, 2, 28);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1900, 3, 1);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1900, 3, 1, 15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1, 1, 1, 15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new TimeSpan(15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new TimeSpan(24, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
}
|
||||
|
||||
Assert.AreEqual(expectedException.GetType(), actualException.GetType());
|
||||
Assert.AreEqual(expectedException.Message, actualException.Message);
|
||||
|
||||
stream.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SheetWriteColumnInformation()
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
using (var helper = new SaveAsExcelFileStreamWriterHelper(stream, true))
|
||||
using (var sheet = helper.AddSheet(null, 7))
|
||||
{
|
||||
sheet.WriteColumnInformation(new[] { 1F, 2F, 3F, 4F, 5F, 6F, 7F });
|
||||
|
||||
var value = new DbCellValue();
|
||||
sheet.AddRow();
|
||||
|
||||
value.IsNull = true;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.IsNull = false;
|
||||
value.RawObject = "";
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = "test string";
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = 3;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = 3.5;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = false;
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = true;
|
||||
sheet.AddCell(value);
|
||||
|
||||
sheet.AddRow();
|
||||
|
||||
value.RawObject = new DateTime(1900, 2, 28);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1900, 3, 1);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1900, 3, 1, 15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new DateTime(1, 1, 1, 15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new TimeSpan(15, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
|
||||
value.RawObject = new TimeSpan(24, 00, 00);
|
||||
sheet.AddCell(value);
|
||||
}
|
||||
|
||||
ContentMatch(stream, "[Content_Types].xml");
|
||||
ContentMatch(stream, "_rels/.rels");
|
||||
ContentMatch(stream, "xl/_rels/workbook.xml.rels");
|
||||
ContentMatch(stream, "xl/styles.xml");
|
||||
ContentMatch(stream, "xl/workbook.xml");
|
||||
ContentMatch(stream, "xl/worksheets/sheet1.xml", "xl/worksheets/sheet1-withColumns.xml");
|
||||
|
||||
stream.Dispose();
|
||||
}
|
||||
|
||||
[GeneratedRegex("\\r?\\n\\s*")]
|
||||
private static partial Regex GetContentRemoveLinebreakLeadingSpaceRegex();
|
||||
|
||||
private void ContentMatch(string fileName)
|
||||
private void ContentMatch(Stream stream, string fileName)
|
||||
{
|
||||
ContentMatch(stream, fileName, fileName);
|
||||
}
|
||||
|
||||
private void ContentMatch(Stream stream, string realFileName, string referenceFileName)
|
||||
{
|
||||
string referencePath = Path.Combine(RunEnvironmentInfo.GetTestDataLocation(),
|
||||
"DataStorage",
|
||||
"SaveAsExcelFileStreamWriterHelperTests",
|
||||
fileName);
|
||||
referenceFileName);
|
||||
string referenceContent = File.ReadAllText(referencePath);
|
||||
referenceContent = GetContentRemoveLinebreakLeadingSpaceRegex().Replace(referenceContent, "");
|
||||
|
||||
using (var zip = new ZipArchive(_stream, ZipArchiveMode.Read, true))
|
||||
using (var zip = new ZipArchive(stream, ZipArchiveMode.Read, true))
|
||||
{
|
||||
using (var reader = new StreamReader(zip?.GetEntry(fileName)?.Open()!))
|
||||
using (var reader = new StreamReader(zip?.GetEntry(realFileName)?.Open()!))
|
||||
{
|
||||
string realContent = reader.ReadToEnd();
|
||||
Assert.AreEqual(referenceContent, realContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public void CheckContentType()
|
||||
{
|
||||
ContentMatch("[Content_Types].xml");
|
||||
}
|
||||
[Test]
|
||||
public void CheckTopRels()
|
||||
{
|
||||
ContentMatch("_rels/.rels");
|
||||
}
|
||||
[Test]
|
||||
public void CheckWorkbookRels()
|
||||
{
|
||||
ContentMatch("xl/_rels/workbook.xml.rels");
|
||||
}
|
||||
[Test]
|
||||
public void CheckStyles()
|
||||
{
|
||||
ContentMatch("xl/styles.xml");
|
||||
}
|
||||
[Test]
|
||||
public void CheckWorkbook()
|
||||
{
|
||||
ContentMatch("xl/workbook.xml");
|
||||
}
|
||||
[Test]
|
||||
public void CheckSheet1()
|
||||
{
|
||||
ContentMatch("xl/worksheets/sheet1.xml");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_stream.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public class SaveAsExcelFileStreamWriterHelperReferenceManagerTests
|
||||
|
||||
Reference in New Issue
Block a user