complete config for reading excel data
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibReadTetraExcel
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
}
|
||||
126
LibReadTetraExcel/ExcelHelper.cs
Normal file
126
LibReadTetraExcel/ExcelHelper.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using LibDataBase;
|
||||
using OfficeOpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
namespace LibReadTetraExcel
|
||||
{
|
||||
public class ExcelHelper
|
||||
{
|
||||
public static OrderConfig ReadOCROrder(string execlFileName, string order)
|
||||
{
|
||||
OrderConfig config = new OrderConfig();
|
||||
try
|
||||
{
|
||||
ExcelPackage.License.SetNonCommercialOrganization("My Noncommercial organization");
|
||||
using (ExcelPackage package = new ExcelPackage(execlFileName))
|
||||
{
|
||||
ExcelWorksheet sheet1 = package.Workbook.Worksheets["P2生成数据"];
|
||||
config.ParseQSV = false;
|
||||
config.ParseProduct = false;
|
||||
config.ParseArrange = false;
|
||||
config.QSV = "";
|
||||
config.NumberOfLanes = 0;
|
||||
for (int i = 1; i < sheet1.Dimension.Rows; i++)
|
||||
{
|
||||
if (sheet1.GetValue(i, 3) == null)
|
||||
continue;
|
||||
if (sheet1.Cells[i, 3].Value.ToString() != order)
|
||||
continue;
|
||||
config.QSV = sheet1.Cells[i, 4].Value.ToString();
|
||||
config.NumberOfLanes = Convert.ToInt32(sheet1.Cells[i, 5].Value.ToString());
|
||||
int num = 0;
|
||||
for (int k = 0; k < 10; k++)
|
||||
{
|
||||
string lanes = sheet1.Cells[i + k, 6].Value.ToString();
|
||||
string design = sheet1.Cells[i + k, 7].Value.ToString().Split('-')[1];
|
||||
string[] tmp = lanes.Substring(1, lanes.Length - 2).Split(',');
|
||||
num += tmp.Length;
|
||||
List<string> textOCR = ExecelGetOcrText(design, sheet1.Cells[i + k, 8].Value.ToString());
|
||||
foreach (string lan in tmp)
|
||||
{
|
||||
int lanInt = Convert.ToInt32(lan);
|
||||
config.OCRRequest[lanInt] = textOCR;
|
||||
config.OCRDesign[lanInt] = design;
|
||||
}
|
||||
|
||||
if (num >= config.NumberOfLanes)
|
||||
{
|
||||
config.ParseQSV = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!config.ParseQSV)
|
||||
return config;
|
||||
|
||||
config.ProductStandard = "";
|
||||
ExcelWorksheet sheet2 = package.Workbook.Worksheets["QSV对应产品规格和梯度"];
|
||||
for (int j = 1; j <= sheet2.Dimension.Rows; j++)
|
||||
{
|
||||
if (sheet2.GetValue(j, 1) == null)
|
||||
continue;
|
||||
if (sheet2.Cells[j, 1].Value.ToString() != config.QSV)
|
||||
continue;
|
||||
config.ProductStandard = sheet2.Cells[j, 2].Value.ToString();
|
||||
config.Width = Convert.ToDouble(sheet2.Cells[j, 3].Value.ToString());
|
||||
config.Height = Convert.ToDouble(sheet2.Cells[j, 4].Value.ToString());
|
||||
config.Gradient = Convert.ToDouble(sheet2.Cells[j, 5].Value.ToString());
|
||||
config.ParseProduct = true;
|
||||
break;
|
||||
}
|
||||
if (!config.ParseProduct)
|
||||
return config;
|
||||
|
||||
ExcelWorksheet sheet3 = package.Workbook.Worksheets["产品规格对应排布方式"];
|
||||
for (int n = 1; n < sheet3.Dimension.Rows; n++)
|
||||
{
|
||||
if (sheet3.GetValue(n, 1) == null)
|
||||
continue;
|
||||
if (sheet3.Cells[n, 1].Value.ToString() != config.ProductStandard)
|
||||
continue;
|
||||
string str = sheet3.Cells[n + config.OCRRequest[1].Count - 1, 4].Value.ToString();
|
||||
string[] x_y = str.Split(',');
|
||||
string[] X = x_y[0].Split(':');
|
||||
string[] Y = x_y[1].Split(':');
|
||||
config.DistX = Convert.ToDouble(X[1].Replace("mm", ""));
|
||||
config.DistY = Convert.ToDouble(Y[1].Replace("mm", ""));
|
||||
|
||||
string alignColor = sheet3.Cells[n + config.OCRRequest[1].Count - 1, 3].Value.ToString();
|
||||
if (alignColor.Contains("单排"))
|
||||
config.ColorMax = config.OCRRequest.Values.Select(x => x.Count).Max();
|
||||
else
|
||||
config.ColorMax = alignColor.Replace("排布", "").Split(',').ToList().Select(int.Parse).Max();
|
||||
config.ColorArray = alignColor;
|
||||
config.ParseArrange = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return config;
|
||||
}
|
||||
private static List<string> ExecelGetOcrText(string design, string layer)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
string[] ll = layer.Replace("[", "").Replace("]", "").Split(',');
|
||||
for (int i = 0; i < ll.Length; i++)
|
||||
{
|
||||
ll[i] = ll[i].Replace(" ", "");
|
||||
string[] str = ll[i].Split('-');
|
||||
if (str.Length < 2)
|
||||
continue;
|
||||
result.Add(design + str[1] + str[0]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\SixLabors.ImageSharp.3.1.12\build\SixLabors.ImageSharp.props" Condition="Exists('..\packages\SixLabors.ImageSharp.3.1.12\build\SixLabors.ImageSharp.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -52,20 +51,11 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BouncyCastle.Cryptography, Version=2.0.0.0, Culture=neutral, PublicKeyToken=072edcf4a5328938, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\BouncyCastle.Cryptography.2.7.0-beta.98\lib\net461\BouncyCastle.Cryptography.dll</HintPath>
|
||||
<Reference Include="EPPlus, Version=8.4.0.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EPPlus.8.4.0\lib\net462\EPPlus.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Enums.NET, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7ea1c1650d506225, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Enums.NET.5.0.0\lib\net461\Enums.NET.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ExtendedNumerics.BigDecimal, Version=3003.0.0.346, Culture=neutral, PublicKeyToken=65f1315a45ad8949, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ExtendedNumerics.BigDecimal.3003.0.0.346\lib\net472\ExtendedNumerics.BigDecimal.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=1.4.2.13, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SharpZipLib.1.4.2\lib\netstandard2.0\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MathNet.Numerics, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cd8b63ad3d691a37, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MathNet.Numerics.Signed.5.0.0\lib\net461\MathNet.Numerics.dll</HintPath>
|
||||
<Reference Include="EPPlus.Interfaces, Version=8.4.0.0, Culture=neutral, PublicKeyToken=a694d7f3b0907a61, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EPPlus.Interfaces.8.4.0\lib\net462\EPPlus.Interfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Bcl.Cryptography, Version=10.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.Cryptography.10.0.1\lib\net462\Microsoft.Bcl.Cryptography.dll</HintPath>
|
||||
@@ -73,28 +63,14 @@
|
||||
<Reference Include="Microsoft.IO.RecyclableMemoryStream, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.IO.RecyclableMemoryStream.3.0.1\lib\netstandard2.0\Microsoft.IO.RecyclableMemoryStream.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI.Core, Version=2.7.5.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.2.7.5\lib\net472\NPOI.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI.OOXML, Version=2.7.5.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.2.7.5\lib\net472\NPOI.OOXML.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI.OpenXml4Net, Version=2.7.5.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.2.7.5\lib\net472\NPOI.OpenXml4Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI.OpenXmlFormats, Version=2.7.5.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.2.7.5\lib\net472\NPOI.OpenXmlFormats.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NSax, Version=1.0.2.0, Culture=neutral, PublicKeyToken=0b3d9671cbd3c8d0, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NSax.1.0.2\lib\net472\NSax.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SixLabors.Fonts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d998eea7b14cab13, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SixLabors.Fonts.1.0.1\lib\netstandard2.0\SixLabors.Fonts.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -115,24 +91,15 @@
|
||||
<Reference Include="System.Security.Cryptography.Xml, Version=10.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Security.Cryptography.Xml.10.0.1\lib\net462\System.Security.Cryptography.Xml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Encoding.CodePages, Version=10.0.0.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Encoding.CodePages.10.0.1\lib\net462\System.Text.Encoding.CodePages.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.6.3\lib\net462\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="ZString, Version=2.6.0.0, Culture=neutral, PublicKeyToken=df4c250b14d82627, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ZString.2.6.0\lib\netstandard2.0\ZString.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Class1.cs" />
|
||||
<Compile Include="ExcelHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -146,12 +113,11 @@
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets" Condition="Exists('..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\SixLabors.ImageSharp.3.1.12\build\SixLabors.ImageSharp.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SixLabors.ImageSharp.3.1.12\build\SixLabors.ImageSharp.props'))" />
|
||||
<Error Condition="!Exists('..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets" Condition="Exists('..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets')" />
|
||||
</Project>
|
||||
@@ -1,24 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="BouncyCastle.Cryptography" version="2.7.0-beta.98" targetFramework="net472" />
|
||||
<package id="Enums.NET" version="5.0.0" targetFramework="net472" />
|
||||
<package id="ExtendedNumerics.BigDecimal" version="3003.0.0.346" targetFramework="net472" />
|
||||
<package id="MathNet.Numerics.Signed" version="5.0.0" targetFramework="net472" />
|
||||
<package id="EPPlus" version="8.4.0" targetFramework="net472" />
|
||||
<package id="EPPlus.Interfaces" version="8.4.0" targetFramework="net472" />
|
||||
<package id="Microsoft.Bcl.Cryptography" version="10.0.1" targetFramework="net472" />
|
||||
<package id="Microsoft.IO.RecyclableMemoryStream" version="3.0.1" targetFramework="net472" />
|
||||
<package id="NPOI" version="2.7.5" targetFramework="net472" />
|
||||
<package id="NSax" version="1.0.2" targetFramework="net472" />
|
||||
<package id="SharpZipLib" version="1.4.2" targetFramework="net472" />
|
||||
<package id="SixLabors.Fonts" version="1.0.1" targetFramework="net472" />
|
||||
<package id="SixLabors.ImageSharp" version="3.1.12" targetFramework="net472" />
|
||||
<package id="System.Buffers" version="4.6.1" targetFramework="net472" />
|
||||
<package id="System.ComponentModel.Annotations" version="5.0.0" targetFramework="net472" />
|
||||
<package id="System.Formats.Asn1" version="10.0.1" targetFramework="net472" />
|
||||
<package id="System.Memory" version="4.6.3" targetFramework="net472" />
|
||||
<package id="System.Numerics.Vectors" version="4.6.1" targetFramework="net472" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.1.2" targetFramework="net472" />
|
||||
<package id="System.Security.Cryptography.Xml" version="10.0.1" targetFramework="net472" />
|
||||
<package id="System.Text.Encoding.CodePages" version="10.0.1" targetFramework="net472" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.6.3" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.6.1" targetFramework="net472" />
|
||||
<package id="ZString" version="2.6.0" targetFramework="net472" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user