System.Data.DataTable dz = new System.Data.DataTable();
dz.Columns.Add("item_no", typeof(string));
dz.Columns.Add("description", typeof(string));
dz.Columns.Add("formular", typeof(string));
Microsoft.Office.Interop.Excel.Application myExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
Workbook myWorkbook = null;
Worksheet mySheet = null;
string excelFileName = @"D:\dll\loss\塑胶金属夹.xls";
// 打开Excel文件
myWorkbook = myExcel.Workbooks.Open(excelFileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
// 获取第一个sheet
mySheet = (Worksheet)myWorkbook.Sheets[1];
for (int i = 9; i < 78; i++)
{
Microsoft.Office.Interop.Excel.Range rg = mySheet.get_Range("C"+i.ToString(), "C"+i.ToString());
dz.Rows.Add(1);
dz.Rows[i-9]["item_no"] = rg.Value2.ToString();
rg = mySheet.get_Range("D"+i.ToString(), "D"+i.ToString());
dz.Rows[i-9]["description"]= rg.Value2.ToString();
rg = mySheet.get_Range("AM" + i.ToString(), "AM" + i.ToString());
if (rg.Formula.ToString().IndexOf("*",0)>0)
{
dz.Rows[i-9]["formular"] = rg.Formula.ToString().Substring(rg.Formula.ToString().IndexOf("*",0)+1,rg.Formula.ToString().Length-rg.Formula.ToString().IndexOf("*",0)-1);
if (dz.Rows[i - 9]["formular"].ToString().IndexOf(",", 0) > 0)
{
dz.Rows[i - 9]["formular"] = dz.Rows[i - 9]["formular"].ToString().Substring(0, dz.Rows[i - 9]["formular"].ToString().IndexOf(",", 0));
}
}
else
{
if(rg.Formula.ToString().Length>0)
{
dz.Rows[i - 9]["formular"] = 1;
}
else
{
dz.Rows[i - 9]["formular"] = rg.Formula.ToString();
}
}
}
dz.DefaultView.Sort = "item_no";
_flexCategories.DataSource = dz;
_flexCategories.SaveExcel(@"D:\dll\损耗\1.xls");
dz.Columns.Add("item_no", typeof(string));
dz.Columns.Add("description", typeof(string));
dz.Columns.Add("formular", typeof(string));
Microsoft.Office.Interop.Excel.Application myExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
Workbook myWorkbook = null;
Worksheet mySheet = null;
string excelFileName = @"D:\dll\loss\塑胶金属夹.xls";
// 打开Excel文件
myWorkbook = myExcel.Workbooks.Open(excelFileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
// 获取第一个sheet
mySheet = (Worksheet)myWorkbook.Sheets[1];
for (int i = 9; i < 78; i++)
{
Microsoft.Office.Interop.Excel.Range rg = mySheet.get_Range("C"+i.ToString(), "C"+i.ToString());
dz.Rows.Add(1);
dz.Rows[i-9]["item_no"] = rg.Value2.ToString();
rg = mySheet.get_Range("D"+i.ToString(), "D"+i.ToString());
dz.Rows[i-9]["description"]= rg.Value2.ToString();
rg = mySheet.get_Range("AM" + i.ToString(), "AM" + i.ToString());
if (rg.Formula.ToString().IndexOf("*",0)>0)
{
dz.Rows[i-9]["formular"] = rg.Formula.ToString().Substring(rg.Formula.ToString().IndexOf("*",0)+1,rg.Formula.ToString().Length-rg.Formula.ToString().IndexOf("*",0)-1);
if (dz.Rows[i - 9]["formular"].ToString().IndexOf(",", 0) > 0)
{
dz.Rows[i - 9]["formular"] = dz.Rows[i - 9]["formular"].ToString().Substring(0, dz.Rows[i - 9]["formular"].ToString().IndexOf(",", 0));
}
}
else
{
if(rg.Formula.ToString().Length>0)
{
dz.Rows[i - 9]["formular"] = 1;
}
else
{
dz.Rows[i - 9]["formular"] = rg.Formula.ToString();
}
}
}
dz.DefaultView.Sort = "item_no";
_flexCategories.DataSource = dz;
_flexCategories.SaveExcel(@"D:\dll\损耗\1.xls");