read excel data
This commit is contained in:
@@ -84,7 +84,7 @@ namespace TetraPackOCR
|
||||
/// <summary>
|
||||
/// 共印依据 QSV Design, Layers, Colours,产品规格
|
||||
/// </summary>
|
||||
string QSV, Colours, ProductStandard;
|
||||
string QSV, ProductStandard;
|
||||
/// <summary>
|
||||
/// 幅数 包材宽 梯度 X距离 Y距离
|
||||
/// </summary>
|
||||
@@ -677,241 +677,123 @@ namespace TetraPackOCR
|
||||
btn_OrderNum.BackColor = Color.DeepSkyBlue;
|
||||
return;
|
||||
}
|
||||
string laststr;
|
||||
if (order.Length > 1)
|
||||
laststr = order.Substring(order.Length - 1);
|
||||
else
|
||||
laststr = order;
|
||||
if (laststr == "C")
|
||||
|
||||
log.Info("当前订单号为:" + order);
|
||||
//读取表格内容
|
||||
ExcelPackage.License.SetNonCommercialOrganization("My Noncommercial organization");
|
||||
using (ExcelPackage package = new ExcelPackage(execlFileName))
|
||||
{
|
||||
log.Info("当前订单号为:" + order);
|
||||
//读取表格内容
|
||||
ExcelPackage.License.SetNonCommercialOrganization("My Noncommercial organization");
|
||||
using (ExcelPackage package = new ExcelPackage(execlFileName))
|
||||
sheet1 = package.Workbook.Worksheets["P2生成数据"];
|
||||
sheet2 = package.Workbook.Worksheets["QSV对应产品规格和梯度"];
|
||||
sheet3 = package.Workbook.Worksheets["产品规格对应排布方式"];
|
||||
//根据订单遍历sheet1 找Sequence QSV NumOFLanes 字符
|
||||
for (int i = 1; i < sheet1.Dimension.Rows; i++)
|
||||
{
|
||||
sheet1 = package.Workbook.Worksheets["P2生成数据"];
|
||||
sheet2 = package.Workbook.Worksheets["QSV对应产品规格和梯度"];
|
||||
sheet3 = package.Workbook.Worksheets["产品规格对应排布方式"];
|
||||
string FirstLayers = "";
|
||||
//根据订单遍历sheet1 找Sequence QSV NumOFLanes 字符
|
||||
for (int i = 1; i < sheet1.Dimension.Rows; i++)
|
||||
if (sheet1.GetValue(i, 3) != null)
|
||||
{
|
||||
if (sheet1.GetValue(i, 3) != null)
|
||||
if (sheet1.Cells[i, 3].Value.ToString() == order)
|
||||
{
|
||||
if (sheet1.Cells[i, 3].Value.ToString() == order)
|
||||
QSV = sheet1.Cells[i, 4].Value.ToString();
|
||||
lbl_QSVShow.Text = QSV;
|
||||
log.Info("当前订单QSV:" + QSV);
|
||||
NumberOfLanes = Convert.ToInt32(sheet1.Cells[i, 5].Value.ToString());
|
||||
log.Info("当前订单Number Of Lanes:" + NumberOfLanes);
|
||||
lbl_NOFShow.Text = sheet1.Cells[i, 5].Value.ToString();
|
||||
|
||||
int num = 0;
|
||||
for (int k = 0; k < 10; k++)
|
||||
{
|
||||
QSV = sheet1.Cells[i, 4].Value.ToString();
|
||||
lbl_QSVShow.Text = QSV;
|
||||
log.Info("当前订单QSV:" + QSV);
|
||||
NumberOfLanes = Convert.ToInt32(sheet1.Cells[i, 5].Value.ToString());
|
||||
log.Info("当前订单Number Of Lanes:" + NumberOfLanes);
|
||||
lbl_NOFShow.Text = sheet1.Cells[i, 5].Value.ToString();
|
||||
FirstLayers = sheet1.Cells[i, 8].Value.ToString();
|
||||
Colours = sheet1.Cells[i, 9].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];
|
||||
lanes = lanes.Substring(1, lanes.Length - 2);
|
||||
string[] tmp = lanes.Split(',');
|
||||
num += tmp.Length;
|
||||
List<string> textOCR = ExecelGetOcrText(design, sheet1.Cells[i + k, 8].Value.ToString());
|
||||
foreach (string lan in tmp)
|
||||
{
|
||||
string lanes = sheet1.Cells[i + k, 6].Value.ToString();
|
||||
string design = sheet1.Cells[i + k, 7].Value.ToString();
|
||||
string layers = sheet1.Cells[i + k, 8].Value.ToString();
|
||||
string colours = sheet1.Cells[i + k, 9].Value.ToString();
|
||||
lanes = lanes.Substring(1, lanes.Length - 2);
|
||||
string[] tmp = lanes.Split(',');
|
||||
num += tmp.Length;
|
||||
foreach (string lan in tmp)
|
||||
{
|
||||
int lanInt = Convert.ToInt32(lan);
|
||||
ocrTextRequest[lanInt] = ExecelGetOcrText(design, layers);
|
||||
ocrTextDesign[lanInt] = design;
|
||||
}
|
||||
listBox1.Items.Add(sheet1.Cells[i + k, 6].Value.ToString());
|
||||
listBox1.Items.Add(string.Join(",", ocrTextRequest[Convert.ToInt32(tmp[0])]));
|
||||
|
||||
if (num >= NumberOfLanes)
|
||||
break;
|
||||
int lanInt = Convert.ToInt32(lan);
|
||||
ocrTextRequest[lanInt] = textOCR;
|
||||
ocrTextDesign[lanInt] = design;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
listBox1.Items.Add(sheet1.Cells[i + k, 6].Value.ToString());
|
||||
listBox1.Items.Add(string.Join(",", textOCR));
|
||||
|
||||
if (!string.IsNullOrEmpty(QSV))
|
||||
{
|
||||
string qsv;
|
||||
//根据得到的QSV遍历sheet2 找产品规格和宽度梯度
|
||||
for (int j = 1; j <= sheet2.Dimension.Rows; j++)
|
||||
{
|
||||
qsv = sheet2.Cells[j, 1].Value.ToString();
|
||||
if (qsv == QSV)
|
||||
{
|
||||
ProductStandard = sheet2.Cells[j, 2].Value.ToString();
|
||||
lbl_ProductStandardShow.Text = ProductStandard;
|
||||
log.Info("当前订单产品编号:" + ProductStandard);
|
||||
width = Convert.ToDouble(sheet2.Cells[j, 3].Value.ToString());
|
||||
lbl_widthShow.Text = sheet2.Cells[j, 3].Value.ToString();
|
||||
log.Info("当前订单幅宽:" + width);
|
||||
Gradient = Convert.ToDouble(sheet2.Cells[j, 4].Value.ToString());
|
||||
lbl_GradientShow.Text = sheet2.Cells[j, 4].Value.ToString();
|
||||
log.Info("当前订单梯度:" + Gradient);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(ProductStandard))
|
||||
{
|
||||
log.Debug("ProductStandard未找到,请检查订单号是否正确");
|
||||
btn_OrderNum.Enabled = true;
|
||||
btn_OrderNum.BackColor = Color.DeepSkyBlue;
|
||||
return;
|
||||
}
|
||||
//根据产品规格获取距离坐标
|
||||
for (int n = 1; n < sheet3.Dimension.Rows; n++)
|
||||
{
|
||||
if (sheet3.GetValue(n, 1) != null)
|
||||
{
|
||||
if (sheet3.Cells[n, 1].Value.ToString() == ProductStandard)
|
||||
{
|
||||
string str = sheet3.Cells[n + FirstLayers.Split(',').Length - 1, 4].Value.ToString();
|
||||
string[] x_y = str.Split(',');
|
||||
string[] X = x_y[0].Split(':');
|
||||
string[] Y = x_y[1].Split(':');
|
||||
DistX = Convert.ToDouble(X[1].Replace("mm", ""));
|
||||
lbl_DistXShow.Text = X[1].Replace("mm", "");
|
||||
log.Info("当前订单X偏移:" + DistX);
|
||||
DistY = Convert.ToDouble(Y[1].Replace("mm", ""));
|
||||
lbl_DistYShow.Text = Y[1].Replace("mm", "");
|
||||
log.Info("当前订单Y偏移:" + DistY);
|
||||
if (num >= NumberOfLanes)
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (DistX == 0 || DistY == 0)
|
||||
{
|
||||
log.Debug("DistX,DistY未找到,请检查订单号是否正确");
|
||||
btn_OrderNum.Enabled = true;
|
||||
btn_OrderNum.BackColor = Color.DeepSkyBlue;
|
||||
return;
|
||||
}
|
||||
log.Info("相关数据已获取完成,且已显示在界面中,请查看。");
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(QSV))
|
||||
{
|
||||
string qsv;
|
||||
//根据得到的QSV遍历sheet2 找产品规格和宽度梯度
|
||||
for (int j = 1; j <= sheet2.Dimension.Rows; j++)
|
||||
{
|
||||
log.Debug("QSV未找到,请检查订单号是否正确");
|
||||
qsv = sheet2.Cells[j, 1].Value.ToString();
|
||||
if (qsv == QSV)
|
||||
{
|
||||
ProductStandard = sheet2.Cells[j, 2].Value.ToString();
|
||||
lbl_ProductStandardShow.Text = ProductStandard;
|
||||
log.Info("当前订单产品编号:" + ProductStandard);
|
||||
width = Convert.ToDouble(sheet2.Cells[j, 3].Value.ToString());
|
||||
lbl_widthShow.Text = sheet2.Cells[j, 3].Value.ToString();
|
||||
log.Info("当前订单幅宽:" + width);
|
||||
Gradient = Convert.ToDouble(sheet2.Cells[j, 4].Value.ToString());
|
||||
lbl_GradientShow.Text = sheet2.Cells[j, 4].Value.ToString();
|
||||
log.Info("当前订单梯度:" + Gradient);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(ProductStandard))
|
||||
{
|
||||
log.Debug("ProductStandard未找到,请检查订单号是否正确");
|
||||
btn_OrderNum.Enabled = true;
|
||||
btn_OrderNum.BackColor = Color.DeepSkyBlue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log.Info("当前订单号为:" + order);
|
||||
//读取表格内容
|
||||
ExcelPackage.License.SetNonCommercialOrganization("My Noncommercial organization");
|
||||
using (ExcelPackage package = new ExcelPackage(execlFileName))
|
||||
{
|
||||
sheet1 = package.Workbook.Worksheets["P2生成数据"];
|
||||
sheet2 = package.Workbook.Worksheets["QSV对应产品规格和梯度"];
|
||||
sheet3 = package.Workbook.Worksheets["产品规格对应排布方式"];
|
||||
string firstLayers = "";
|
||||
//根据订单遍历sheet1 找QSV NumOFLanes 字符
|
||||
for (int i = 1; i < sheet1.Dimension.Rows; i++)
|
||||
//根据产品规格获取距离坐标
|
||||
for (int n = 1; n < sheet3.Dimension.Rows; n++)
|
||||
{
|
||||
if (sheet1.GetValue(i, 3) != null)
|
||||
if (sheet3.GetValue(n, 1) != null)
|
||||
{
|
||||
if (sheet1.Cells[i, 3].Value.ToString() == order)
|
||||
if (sheet3.Cells[n, 1].Value.ToString() == ProductStandard)
|
||||
{
|
||||
QSV = sheet1.Cells[i, 4].Value.ToString();
|
||||
lbl_QSVShow.Text = QSV;
|
||||
log.Info("当前订单QSV:" + QSV);
|
||||
NumberOfLanes = Convert.ToInt32(sheet1.Cells[i, 5].Value.ToString());
|
||||
log.Info("当前订单Number Of Lanes:" + NumberOfLanes);
|
||||
lbl_NOFShow.Text = sheet1.Cells[i, 5].Value.ToString();
|
||||
|
||||
//获取字符 并显示在界面还需处理先预留在这
|
||||
string design = sheet1.Cells[i, 7].Value.ToString();
|
||||
firstLayers = sheet1.Cells[i, 8].Value.ToString();
|
||||
Colours = sheet1.Cells[i, 9].Value.ToString();
|
||||
|
||||
for (int lan = 1; lan <= NumberOfLanes; lan++)
|
||||
{
|
||||
ocrTextRequest[lan] = ExecelGetOcrText(design, firstLayers);
|
||||
ocrTextDesign[lan] = design;
|
||||
}
|
||||
listBox1.Items.Add(sheet1.Cells[i, 6].Value.ToString());
|
||||
listBox1.Items.Add(string.Join(",", ocrTextRequest[1]));
|
||||
string str = sheet3.Cells[n + ocrTextRequest[1].Count - 1, 4].Value.ToString();
|
||||
string[] x_y = str.Split(',');
|
||||
string[] X = x_y[0].Split(':');
|
||||
string[] Y = x_y[1].Split(':');
|
||||
DistX = Convert.ToDouble(X[1].Replace("mm", ""));
|
||||
lbl_DistXShow.Text = X[1].Replace("mm", "");
|
||||
log.Info("当前订单X偏移:" + DistX);
|
||||
DistY = Convert.ToDouble(Y[1].Replace("mm", ""));
|
||||
lbl_DistYShow.Text = Y[1].Replace("mm", "");
|
||||
log.Info("当前订单Y偏移:" + DistY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(QSV))
|
||||
if (DistX == 0 || DistY == 0)
|
||||
{
|
||||
string qsv;
|
||||
//根据得到的QSV遍历sheet2 找产品规格和宽度梯度
|
||||
for (int j = 1; j <= sheet2.Dimension.Rows; j++)
|
||||
{
|
||||
qsv = sheet2.Cells[j, 1].Value.ToString();
|
||||
if (qsv == QSV)
|
||||
{
|
||||
ProductStandard = sheet2.Cells[j, 2].Value.ToString();
|
||||
lbl_ProductStandardShow.Text = ProductStandard;
|
||||
log.Info("当前订单产品编号:" + ProductStandard);
|
||||
width = Convert.ToDouble(sheet2.Cells[j, 3].Value.ToString());
|
||||
lbl_widthShow.Text = sheet2.Cells[j, 3].Value.ToString();
|
||||
log.Info("当前订单幅宽:" + width);
|
||||
Gradient = Convert.ToDouble(sheet2.Cells[j, 4].Value.ToString());
|
||||
lbl_GradientShow.Text = sheet2.Cells[j, 4].Value.ToString();
|
||||
log.Info("当前订单梯度:" + Gradient);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(ProductStandard))
|
||||
{
|
||||
log.Debug("ProductStandard未找到,请检查订单号是否正确");
|
||||
btn_OrderNum.Enabled = true;
|
||||
btn_OrderNum.BackColor = Color.DeepSkyBlue;
|
||||
return;
|
||||
}
|
||||
//根据产品规格获取距离坐标
|
||||
for (int n = 1; n < sheet3.Dimension.Rows; n++)
|
||||
{
|
||||
if (sheet3.GetValue(n, 1) != null)
|
||||
{
|
||||
if (sheet3.Cells[n, 1].Value.ToString() == ProductStandard)
|
||||
{
|
||||
string str = sheet3.Cells[n + firstLayers.Split(',').Length - 1, 4].Value.ToString();
|
||||
string[] x_y = str.Split(',');
|
||||
string[] X = x_y[0].Split(':');
|
||||
string[] Y = x_y[1].Split(':');
|
||||
DistX = Convert.ToDouble(X[1].Replace("mm", ""));
|
||||
lbl_DistXShow.Text = X[1].Replace("mm", "");
|
||||
log.Info("当前订单X偏移:" + DistX);
|
||||
DistY = Convert.ToDouble(Y[1].Replace("mm", ""));
|
||||
lbl_DistYShow.Text = Y[1].Replace("mm", "");
|
||||
log.Info("当前订单Y偏移:" + DistY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (DistX == 0 || DistY == 0)
|
||||
{
|
||||
log.Debug("DistX,DistY未找到,请检查订单号是否正确");
|
||||
btn_OrderNum.Enabled = true;
|
||||
btn_OrderNum.BackColor = Color.DeepSkyBlue;
|
||||
return;
|
||||
}
|
||||
log.Info("相关数据已获取完成,且已显示在界面中,请查看。");
|
||||
}
|
||||
else
|
||||
{
|
||||
log.Debug("QSV未找到,请检查订单号是否正确");
|
||||
log.Debug("DistX,DistY未找到,请检查订单号是否正确");
|
||||
btn_OrderNum.Enabled = true;
|
||||
btn_OrderNum.BackColor = Color.DeepSkyBlue;
|
||||
return;
|
||||
}
|
||||
log.Info("相关数据已获取完成,且已显示在界面中,请查看。");
|
||||
}
|
||||
else
|
||||
{
|
||||
log.Debug("QSV未找到,请检查订单号是否正确");
|
||||
btn_OrderNum.Enabled = true;
|
||||
btn_OrderNum.BackColor = Color.DeepSkyBlue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
///判断当前Lans决定结果显示数量
|
||||
|
||||
//判断当前Lans决定结果显示数量
|
||||
InitLableColumn();
|
||||
|
||||
btn_OrderNum.Enabled = true;
|
||||
@@ -1125,9 +1007,6 @@ namespace TetraPackOCR
|
||||
private List<string> ExecelGetOcrText(string design, string layer)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
string[] dd = design.Split('-');
|
||||
if (dd.Length < 2)
|
||||
return result;
|
||||
string[] ll = layer.Replace("[", "").Replace("]", "").Split(',');
|
||||
for (int i = 0; i < ll.Length; i++)
|
||||
{
|
||||
@@ -1135,7 +1014,7 @@ namespace TetraPackOCR
|
||||
string[] str = ll[i].Split('-');
|
||||
if (str.Length < 2)
|
||||
continue;
|
||||
result.Add(dd[1] + str[1] + str[0]);
|
||||
result.Add(design + str[1] + str[0]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1144,7 +1023,7 @@ namespace TetraPackOCR
|
||||
/// </summary>
|
||||
void ClearData()
|
||||
{
|
||||
QSV = null; Colours = null; ProductStandard = null;
|
||||
QSV = null; ProductStandard = null;
|
||||
NumberOfLanes = 0; width = 0; Gradient = 0; DistX = 0; DistY = 0;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -1538,16 +1417,13 @@ namespace TetraPackOCR
|
||||
try
|
||||
{
|
||||
OCRTextResult result = new OCRTextResult();
|
||||
|
||||
List<string> lastocr = new List<string>();
|
||||
OCRResult ocrResult = Engine.DetectText(ocrimagebyte);
|
||||
|
||||
List<Point> pointsList = new List<Point>();
|
||||
|
||||
string[] sd = ocrTextDesign[mMatchingStr].Split('-');
|
||||
foreach (var item in ocrResult.TextBlocks) //将检测框绘制在图片上
|
||||
foreach (var item in ocrResult.TextBlocks)
|
||||
{
|
||||
if (item.Text.Contains(sd[1]))
|
||||
if (item.Text.Contains(ocrTextDesign[mMatchingStr]))
|
||||
{
|
||||
result.points = item.BoxPoints.Select(x => new PointF() { X = x.X, Y = x.Y }).ToArray();
|
||||
pointsList.Add(new Point(item.BoxPoints[0].X, item.BoxPoints[0].Y, item.Text));
|
||||
@@ -1633,8 +1509,7 @@ namespace TetraPackOCR
|
||||
private string GETOCR(List<string> readOCR, string design)
|
||||
{
|
||||
string ocrresult = "";
|
||||
string[] d = design.Split('-');
|
||||
string pattern = @"" + d[1] + "[A-Z0-9]{8}";
|
||||
string pattern = @"" + design + "[A-Z0-9]{8}";
|
||||
for (int i = 0; i < readOCR.Count; i++)
|
||||
{
|
||||
readOCR[i] = readOCR[i].Replace("_", "");
|
||||
@@ -2016,11 +1891,8 @@ namespace TetraPackOCR
|
||||
private void sendToPLC(double x, double y, double r)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] col = Colours.Split(',');
|
||||
|
||||
{
|
||||
float xx = (float)x;
|
||||
|
||||
float yy = (float)y;
|
||||
float rr = (float)r;
|
||||
List<float> ocrxx = new List<float>();
|
||||
@@ -2029,7 +1901,7 @@ namespace TetraPackOCR
|
||||
switch (ProductStandard)
|
||||
{
|
||||
case "TBA1000Slim":
|
||||
switch (col.Length)
|
||||
switch (ocrTextRequest[1].Count)
|
||||
{
|
||||
case 1:
|
||||
xx = (float)x - 9.5f;
|
||||
@@ -2052,7 +1924,7 @@ namespace TetraPackOCR
|
||||
}
|
||||
break;
|
||||
case "TBA250B":
|
||||
switch (col.Length)
|
||||
switch (ocrTextRequest[1].Count)
|
||||
{
|
||||
case 1:
|
||||
xx = (float)x - 9.5f;
|
||||
@@ -2075,7 +1947,7 @@ namespace TetraPackOCR
|
||||
}
|
||||
break;
|
||||
case "TBA125Slim":
|
||||
switch (col.Length)
|
||||
switch (ocrTextRequest[1].Count)
|
||||
{
|
||||
case 1:
|
||||
xx = (float)x - 9.5f;
|
||||
@@ -2098,7 +1970,7 @@ namespace TetraPackOCR
|
||||
}
|
||||
break;
|
||||
case "TPA250SQ":
|
||||
switch (col.Length)
|
||||
switch (ocrTextRequest[1].Count)
|
||||
{
|
||||
case 1:
|
||||
xx = (float)x - 9.5f;
|
||||
@@ -2121,7 +1993,7 @@ namespace TetraPackOCR
|
||||
}
|
||||
break;
|
||||
case "TPA200SQ":
|
||||
switch (col.Length)
|
||||
switch (ocrTextRequest[1].Count)
|
||||
{
|
||||
case 1:
|
||||
xx = (float)x - 9.5f;
|
||||
|
||||
Reference in New Issue
Block a user