none
请问在.net core中如何支持 OleDbDataAdapter ? RRS feed

  • 问题


  • public static DataTable getExcelTable(string ExcelFile, string sheetName)

    { DataSet ds = new DataSet(); //string strConn = "Provider=Microsoft.Ace.OleDb.12.0;Data Source= " + ExcelFile + "; Extended Properties='Excel 12.0;HDR=No'"; string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + ExcelFile + "; Extended Properties='Excel 8.0;HDR=No'"; OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetName + "$]", strConn); oada.Fill(ds); return ds.Tables[0]; }

    不知道怎么回事,无法添加程序集



    • 已编辑 尺蠖 2018年12月19日 7:31
    2018年12月19日 7:27

全部回复

  • 刚才有个高手回复,原来在.net core中已经不能这样读取excel了,需要使用npoi等包,用nuget查找安装
    2018年12月19日 8:26
  • 你好,

    据我所知,OLEDB是一种Windows(唯一)技术。

    但是ASP.NET Core是一种跨平台技术,所以以前的OLEDB的类库不能在ASP.NET Core中使用。

    我建议你可以尝试使用closedxml


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年12月20日 5:43
  • 好的,非常感谢
    2018年12月21日 7:44
  •      public int  CheckResultExcelExportClosedXML(string regionCode,string serverPath,out string saveFile)
            {
                string queryString = "select  *a,b,c from  ....";
                DataSet domainlData = SQLHelper.GetBusinessData(queryString);
                string v_dataSource = "", v_corpName = "", v_websiteRecodNumber, v_domain = "", v_accessIP = "", v_checkResult = "";
    
                Random random = new Random();
                string v_tail = (random.Next(1000).ToString());
                v_tail = "00" + v_tail;
                v_tail = v_tail.Substring(v_tail.Length - 3);
                saveFile = "Result"+v_tail+".xlsx";
    
                int x = 2;
                using (var workbook = new XLWorkbook())
                {
                    var ws = workbook.Worksheets.Add("sheet1");
    
                   
    
                    ws.Cell(1, 1).Value = "数";
                    ws.Cell(1, 2).Value = "公";
                    ws.Cell(1, 3).Value = "网";
                    ws.Cell(1, 4).Value = "域";
                    ws.Cell(1, 5).Value = "接";
                    ws.Cell(1, 6).Value = "稽核结果";
    
    
                    foreach (DataRow row in domainlData.Tables["result"].Rows)
                    {
                        v_dataSource = Convert.ToString(row["dataSource"].ToString());
                        v_corpName = Convert.ToString(row["corpName"].ToString());
                        v_websiteRecodNumber = Convert.ToString(row["websiteRecodNumber"].ToString());
                        v_domain = Convert.ToString(row["domain"].ToString());
                        v_accessIP = Convert.ToString(row["accessIP"].ToString());
                        v_checkResult = Convert.ToString(row["checkResult"].ToString());
                        ws.Cell(x, 1).Value = v_dataSource;
                        ws.Cell(x, 2).Value = v_corpName;
                        ws.Cell(x, 3).Value = v_websiteRecodNumber;
                        ws.Cell(x, 4).Value = v_domain;
                        ws.Cell(x, 5).Value = v_accessIP;
                        ws.Cell(x, 6).Value = v_checkResult;
                        x++;
                    }
                    workbook.SaveAs(serverPath+"//"+saveFile);
                }
    
                 
                return 0;
            }
    closedxml 确实蛮好用的

    • 已编辑 尺蠖 2019年1月8日 6:32
    2019年1月8日 6:30