54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using OfficeOpenXml;
|
|
|
|
namespace ReadFromExcel1
|
|
{
|
|
class Excel
|
|
{
|
|
public Excel()
|
|
{
|
|
|
|
}
|
|
|
|
public string[] ParseExcelData(string excelPath)
|
|
{
|
|
string[] sheetMetalValues = new string[5];
|
|
|
|
try
|
|
{
|
|
var fi = new FileInfo(excelPath);
|
|
using (var p = new ExcelPackage(fi))
|
|
{
|
|
//Get the Worksheet created in the previous codesample.
|
|
var ws = p.Workbook.Worksheets["Werte"];
|
|
|
|
for (int i = 1; i <= ws.Dimension.End.Row; i++)
|
|
{
|
|
if (ws.Cells[i, 1].Value != null)
|
|
{
|
|
if (ws.Cells[i, 1].Value.ToString() == "2")
|
|
{
|
|
sheetMetalValues[0] = ws.Cells[i, 1].Value.ToString();
|
|
sheetMetalValues[1] = ws.Cells[i, 2].Value.ToString();
|
|
sheetMetalValues[2] = ws.Cells[i, 3].Value.ToString();
|
|
sheetMetalValues[3] = ws.Cells[i, 4].Value.ToString();
|
|
sheetMetalValues[4] = ws.Cells[i, 5].Value.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return sheetMetalValues;
|
|
}
|
|
}
|
|
}
|