如何将单元格值导入数组以插入到数据库或对象中?

我正在处理如何从一个Excel文件导入到不同的表中的信息,问题是,我已经实现了下面的代码,但在执行它的时候,我不能看到我是否已经正确地读取细胞,现在阅读后,我想开始分类什么信息我感兴趣,然后select什么信息我应该插入到一个对象或数据库

using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Web; using System.Text; using Microsoft.CSharp; using Microsoft.Office.Interop.Excel; using System.Linq; using System.Runtime.InteropServices; namespace WebApplication2 { public class ImportExcel { public void GetValuesExcel() { Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook xlWorkBook = xlApp.Workbooks.Open(@"C:\Users\JULIO.xlsx"); Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet = xlWorkBook.Sheets[1]; Microsoft.Office.Interop.Excel.Range xlRange = xlWorkSheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; for (int i = 1; i <= rowCount; i++) { for (int j = 1; j <= colCount; j++) { //new line if (j == 1) Console.Write("\r\n"); //write the value to the console if (xlRange.Cells[i, j] != null) Console.Write(xlRange.Cells[i, j].ToString() + "\t"); } } //cleanup GC.Collect(); GC.WaitForPendingFinalizers(); //rule of thumb for releasing com objects: // never use two dots, all COM objects must be referenced and released individually // ex: [somthing].[something].[something] is bad //release com objects to fully kill excel process from running in the background Marshal.ReleaseComObject(xlRange); Marshal.ReleaseComObject(xlWorkSheet); //close and release xlWorkBook.Close(); Marshal.ReleaseComObject(xlWorkBook); //quit and release xlApp.Quit(); Marshal.ReleaseComObject(xlApp); } public void Main(string[] args) { GetValuesExcel(); } } } 

Excel表格包含以下行:

  1. 用户名
  2. 创build
  3. date
  4. 成本
  5. 出发date
  6. 到达date