87 lines
1.9 KiB
C#
87 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using OfficeOpenXml;
|
|
using System.IO;
|
|
using System.Data;
|
|
|
|
namespace friction
|
|
{
|
|
public class DataHandler
|
|
{
|
|
DataTable m_Data = new DataTable();
|
|
|
|
List<string> m_Material1 = new List<string>();
|
|
List<string> m_Material2 = new List<string>();
|
|
|
|
public void LoadData2(string strFileName)
|
|
{
|
|
FileInfo newFile = new FileInfo(strFileName);
|
|
ExcelPackage package = new ExcelPackage(newFile);
|
|
ExcelWorksheet Sheet = package.Workbook.Worksheets[1];
|
|
|
|
m_Data.Clear();
|
|
|
|
// read column
|
|
for (int iCol = Sheet.Dimension.Start.Column; iCol <= Sheet.Dimension.End.Column; iCol++)
|
|
{
|
|
string strCol = (string)Sheet.Cells[Sheet.Dimension.Start.Row, iCol].Value;
|
|
m_Data.Columns.Add(new DataColumn(strCol));
|
|
}
|
|
|
|
// read data
|
|
for (int iRow = Sheet.Dimension.Start.Row + 1; iRow <= Sheet.Dimension.End.Row; iRow++)
|
|
{
|
|
DataRow newRow = m_Data.NewRow();
|
|
|
|
for (int iCol = Sheet.Dimension.Start.Column; iCol <= Sheet.Dimension.End.Column; iCol++)
|
|
{
|
|
var value = Sheet.Cells[iRow, iCol].Value;
|
|
|
|
if (value is double)
|
|
{
|
|
float fData = (float)(double)value;
|
|
newRow[iCol-1] = fData;
|
|
}
|
|
else
|
|
{
|
|
string strData = "";
|
|
if (value != null)
|
|
strData = (string)value;
|
|
|
|
newRow[iCol-1] = strData;
|
|
}
|
|
}
|
|
|
|
m_Data.Rows.Add(newRow);
|
|
}
|
|
|
|
m_Material1 = (from r in m_Data.AsEnumerable()
|
|
select r["Material spring"]).Distinct().Cast<string>().ToList();
|
|
|
|
m_Material2 = (from r in m_Data.AsEnumerable()
|
|
select r["material 2 table"]).Distinct().Cast<string>().ToList();
|
|
|
|
|
|
Console.WriteLine("end");
|
|
}
|
|
|
|
public List<string> GetMaterial1()
|
|
{
|
|
return m_Material1;
|
|
}
|
|
|
|
public List<string> GetMaterial2()
|
|
{
|
|
return m_Material2;
|
|
}
|
|
|
|
public DataTable GetData()
|
|
{
|
|
return m_Data;
|
|
}
|
|
}
|
|
}
|