public string[] getExcelSheetName(String filename) { Common.NPOIExcelExample NPOIexcel = new Common.NPOIExcelExample(); //获取个数 string[] sheetname = NPOIexcel.getExcelSheetSum(filename); //获取表名 // string[] sheetname=new string[k];//表名 //for (int t = 0; t < sheetname.Count(); t++) //{ // InterBoxLableWind.comsheetname.Items.Add(Convert.ToString(sheetname[t])); // // sheetname[t]= NPOIexcel.getExcelSheetName(filename,t); // // sheetname[t] = workbook.GetSheetName(t); //} return(sheetname); }
public DataTable ExcelRead(String filename, string sheetname, int headno) { Common.NPOIExcelExample NPOIexcel = new Common.NPOIExcelExample(); //获取个数 // string[] sheetname = NPOIexcel.getExcelSheetSum(filename); //获取表名 // string[] sheetname=new string[k];//表名 //for (int t = 0; t < sheetname.Count(); t++) //{ // InterBoxLableWind.comsheetname.Items.Add(Convert.ToString(sheetname[t])); // // sheetname[t]= NPOIexcel.getExcelSheetName(filename,t); // // sheetname[t] = workbook.GetSheetName(t); //} //返回表名 // comsheetname.Items.Add("111"); // string sheetname= comsheetname.SelectedItem.ToString(); MODEL.doc_InnerBox[] innerboxs = NPOIexcel.ExcelRead(filename, sheetname, headno); if (innerboxs == null) { return(null); } /*本地表*/ //创建本地表 DataTable table = new DataTable(); table.Columns.Add("Guid", typeof(SqlGuid)); table.Columns.Add("InnerBarcode"); table.Columns.Add("StyleCode"); table.Columns.Add("Name"); table.Columns.Add("Color"); table.Columns.Add("Size"); table.Columns.Add("Type"); table.Columns.Add("Style"); table.Columns.Add("NewCode"); table.Columns.Add("CustomName"); try { for (int i = 0; i < innerboxs.Count(); i++) { Guid guid = Guid.NewGuid(); String InnerBarcode = Convert.ToString(innerboxs[i].InnerBarcode); String StyleCode = Convert.ToString(innerboxs[i].StyleCode); String Color = Convert.ToString(innerboxs[i].Color); String Size = Convert.ToString(innerboxs[i].Size); String Type = Convert.ToString(innerboxs[i].Type); String Style = Convert.ToString(innerboxs[i].Style); String Name = Convert.ToString(innerboxs[i].Name); String NewCode = Convert.ToString(innerboxs[i].NewCode); String CustomName = Convert.ToString(innerboxs[i].CustomName); //本地表加入数据 Unique DataRow row = table.NewRow(); row["Guid"] = guid; row["InnerBarcode"] = InnerBarcode; row["StyleCode"] = StyleCode; row["Name"] = Name; row["Color"] = Color; row["Size"] = Size; row["Type"] = Type; row["Style"] = Style; row["NewCode"] = NewCode; row["CustomName"] = CustomName; table.Rows.Add(row); /*************/ } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return(table); }