code refactoring

This commit is contained in:
wei 2021-05-21 12:06:15 +08:00
parent 2c920d6dc7
commit 7fd2d3ebfd
3 changed files with 32 additions and 44 deletions

View File

@ -999,12 +999,12 @@ private IEnumerable<Dictionary<string, object>> GetOrders(string lang, string ro
if (lang == "zh-CN")
{
newOrder.Add("客戶編號", order.CustomerID);
newOrder.Add("訂單編號", order.OrderNo);
newOrder.Add("產品編號", order.ProductID);
newOrder.Add("量", order.Qty);
newOrder.Add("客户编号", order.CustomerID);
newOrder.Add("订单编号", order.OrderNo);
newOrder.Add("产品编号", order.ProductID);
newOrder.Add("量", order.Qty);
if (role == "Sales")
newOrder.Add("格", order.Amt);
newOrder.Add("格", order.Amt);
yield return newOrder;
}
else if (lang == "en-US")

View File

@ -12,18 +12,40 @@ namespace MiniExcelLibs.OpenXml
{
private readonly static UTF8Encoding Utf8WithBom = new System.Text.UTF8Encoding(true);
internal static string DefaultRels = @"<?xml version=""1.0"" encoding=""utf-8""?>
private static string DefaultRels = @"<?xml version=""1.0"" encoding=""utf-8""?>
<Relationships xmlns=""http://schemas.openxmlformats.org/package/2006/relationships"">
<Relationship Type=""http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"" Target=""/xl/workbook.xml"" Id=""Rfc2254092b6248a9"" />
</Relationships>";
internal static string DefaultWorkbookXmlRels = @"<?xml version=""1.0"" encoding=""utf-8""?>
private static string DefaultWorkbookXmlRels = @"<?xml version=""1.0"" encoding=""utf-8""?>
<Relationships xmlns=""http://schemas.openxmlformats.org/package/2006/relationships"">
{{sheets}}
<Relationship Type=""http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"" Target=""/xl/styles.xml"" Id=""R3db9602ace774fdb"" />
</Relationships>";
internal static string DefaultStylesXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
private static string NoneStylesXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<x:styleSheet xmlns:x=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"">
<x:fonts>
<x:font />
</x:fonts>
<x:fills>
<x:fill />
</x:fills>
<x:borders>
<x:border />
</x:borders>
<x:cellStyleXfs>
<x:xf />
</x:cellStyleXfs>
<x:cellXfs>
<x:xf />
<x:xf />
<x:xf />
<x:xf numFmtId=""14"" applyNumberFormat=""1"" />
</x:cellXfs>
</x:styleSheet>";
private static string DefaultStylesXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<x:styleSheet xmlns:x=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"">
<x:numFmts count=""1"">
<x:numFmt numFmtId=""0"" formatCode="""" />
@ -124,7 +146,7 @@ namespace MiniExcelLibs.OpenXml
</x:cellStyles>
</x:styleSheet>";
internal static string DefaultWorkbookXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
private static string DefaultWorkbookXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<x:workbook xmlns:r=""http://schemas.openxmlformats.org/officeDocument/2006/relationships""
xmlns:x=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"">
<x:sheets>
@ -132,7 +154,6 @@ namespace MiniExcelLibs.OpenXml
</x:sheets>
</x:workbook>";
private static Dictionary<string, XmlDocument> Xmls = new Dictionary<string, XmlDocument>();
private static readonly XmlNamespaceManager _ns;
@ -174,27 +195,7 @@ namespace MiniExcelLibs.OpenXml
if (configuration.TableStyles == TableStyles.None)
{
styleXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<x:styleSheet xmlns:x=""http://schemas.openxmlformats.org/spreadsheetml/2006/main"">
<x:fonts>
<x:font />
</x:fonts>
<x:fills>
<x:fill />
</x:fills>
<x:borders>
<x:border />
</x:borders>
<x:cellStyleXfs>
<x:xf />
</x:cellStyleXfs>
<x:cellXfs>
<x:xf />
<x:xf />
<x:xf />
<x:xf numFmtId=""14"" applyNumberFormat=""1"" />
</x:cellXfs>
</x:styleSheet>";
styleXml = NoneStylesXml;
}
else if (configuration.TableStyles == TableStyles.Default)
{

View File

@ -73,19 +73,6 @@ namespace MiniExcelLibs.OpenXml
}
}
//public void AddSheet(object value, string sheetName, bool printHeader, IConfiguration configuration)
//{
// //TODO:update
// using (var archive = new MiniExcelZipArchive(_stream, ZipArchiveMode.Create, true, _utf8WithBom))
// {
// var packages = DefualtOpenXml.GenerateDefaultOpenXml(archive, sheetName);
// var sheetPath = "xl/worksheets/sheet1.xml";
// CreateSheetXml(value, printHeader, archive, packages, sheetPath);
// GenerateContentTypesXml(archive, packages);
// }
//}
private void CreateSheetXml(object value, bool printHeader, MiniExcelZipArchive archive, Dictionary<string, ZipPackageInfo> packages, string sheetPath)
{
ZipArchiveEntry entry = archive.CreateEntry(sheetPath);