一、使用Excel的目的
使用Excel主要是为了应对大量数据,或者有些现有的数据需要读入到程序当中,减少输入时间以及界面的布置时间,只需要把需要数据输入到表格中即可
二、Excel的读取方式
Excel的读取方式是C#,与Solidworks没有关系,代码展示如下
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=路径+名称.xls;Extended Properties='Excel 8.0;HDR=NO;IMEX=1';";//YES不读取第一排,NO读取第一排
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
string sql = "Select * from [sheet1$]";
OleDbDataAdapter adapter = new OleDbDataAdapter(sql, connection);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
connection.Close();
DataTableCollection tableCollection = dataset.Tables;
DataTable table = tableCollection[0];
DataRowCollection rowCollection = table.Rows;
foreach (DataRow row in rowCollection)
{
for (int i = 0; i < 8; i++)
{
name1[w] = Convert.ToString(row[0]);//提前定义的字符串存储
name2[w] = Convert.ToString(row[1]);
}
w++;
}
三、与Solidworks的相互结合
将读取的表格数据存储在字符串中,这样在使用数据时直接读取字符串即可。