询问者
请问在.net core中如何支持 OleDbDataAdapter ?

问题
-
不知道怎么回事,无法添加程序集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
全部回复
-
你好,
据我所知,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.- 已建议为答案 Brando Zhang 2018年12月24日 1:24
-
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