0

我正在使用 ssis 脚本任务将 excel 表加载到数据表中。我正在使用下面的代码来阅读工作表。这里一个 InvoiceDate 列单元格格式为 Excel 中的日期(dd/mm/yyyy),所有列(30/04/2020)读取正确,但 invoicedate 一个单元格的值30.4.2020返回为空到数据表中。任何人都可以请帮助我要摆脱这个。我的代码是:

var directory = new DirectoryInfo(FolderPath);
FileInfo[] files = directory.GetFiles();


//Declare and initilize variables
string fileFullPath = "";

foreach (FileInfo file in files)
{
    fileFullPath = FolderPath + "\\" + file.Name;

    //Create Excel Connection
    string ConStr;
    string HDR;

    HDR = "YES";
    ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileFullPath + ";Extended Properties=\"Excel 12.0;HDR=" + HDR + ";IMEX=0\"";
    OleDbConnection cnn = new OleDbConnection(ConStr);

    //Get Sheet Name
    cnn.Open();
    DataTable dtSheet = cnn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
    DataRow drSheet = dtSheet.Rows[0];
    string sheetname;
    sheetname = drSheet["TABLE_NAME"].ToString();
    //Load the DataTable with Sheet Data so we can get the column header for Customer
    OleDbCommand Header_conn = new OleDbCommand("select top 1 * from [" + sheetname + "]", cnn);
    OleDbDataAdapter Header_adp = new OleDbDataAdapter(Header_conn);
    DataTable Header_dt = new DataTable();
    Header_adp.Fill(Header_dt);

    //Load excel data into datatable
    string EBIXSQLColumnList = "[Billing Month],[CDW Invoice Date],[CDW Invoice No]";
    OleDbConnection con = new OleDbConnection(ConStr);
    con.Open();
    OleDbCommand EBIX_conn1 = new OleDbCommand("select " + EBIXSQLColumnList + " from [" + sheetname + "]", con);
    OleDbDataAdapter EBIX_adp1 = new OleDbDataAdapter(EBIX_conn1);
    DataTable EBIX_dt1 = new DataTable();
    EBIX_adp1.Fill(EBIX_dt1);
    con.Close();                        
}

我认为stackoverflow没有excel文件附件选项,所以我添加了我的excel表的截图供您参考。 在此处输入图像描述

提前致谢

4

0 回答 0