读取excel文件,遍历sheet,读取内容,存入数据库。
XSSFWorkbook workbook = new XSSFWorkbook(path);
XSSFSheet sheet = workbook.GetSheet(shetName);
XSSFRow row = sheet.GetRow(i);
XSSFCell cell=row.GetCell(j);
一张sheet里面的数据你能取到,为什么不能取到二张sheet里面的数据呢?
根据sheet名子去取数据就行了。
用npoi 这个插件比较方便,个人觉得
mark下先,盼有代码发出来
Microsoft.Office.Interop.Excel.Worksheet ws = new Microsoft.Office.Interop.Excel.Worksheet();
object missing = System.Reflection.Missing.Value;
Application excel = new Application();
Workbook wb = null;
excel.Visible = false;
excel.UserControl = true;
// 以只读的形式打开EXCEL文件
wb = excel.Application.Workbooks.Open(strFileName, missing, true, missing, missing, missing, missing, missing, missing, true, missing, missing, missing, missing, missing);
ws = (Worksheet)wb.Worksheets.get_Item(1);//取得第一个工作薄