导入代码asp .net

时间:2017-02-16 12:54:52

标签: c# asp.net

导入代码

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

  if (flexcel.HasFile)
            {
                string fileExtension = System.IO.Path.GetExtension(flexcel.FileName);

                if (fileExtension == ".xls" || fileExtension == ".xlsx")
                {
                    string fileLocation = Server.MapPath("../Content/MailMarketing/") + flexcel.FileName + month;

                    if (System.IO.File.Exists(fileLocation))
                    {

                        // System.IO.File.Delete(fileLocation);
                    }
                    flexcel.SaveAs(fileLocation);
                    string excelConnectionString = string.Empty;
                    excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
                    Server.MapPath("~/Content/MailMarketing/" ) + flexcel.FileName + month + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                    //connection String for xls file format.
                    if (fileExtension == ".xls")
                    {
                        excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                        fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
                    }
                    //connection String for xlsx file format.
                    else if (fileExtension == ".xlsx")
                    {
                        excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
                        Server.MapPath("~/Content/MailMarketing/") + flexcel.FileName + month + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
                    }
                    //Create Connection to Excel work book and add oledb namespace
                    OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
                    excelConnection.Open();

如何解决?

我已经下载了这个软件,但仍然没有工作......有什么建议吗?

https://www.microsoft.com/en-us/download/details.aspx?id=23734

我尝试了很多代码,但同样的问题......所以有任何建议???

1 个答案:

答案 0 :(得分:0)

无需担心只有oledb ..还有很多其他方法用于上传.xlsx文件(导入)。

以下是标题:

import {Headers, RequestOptions} from 'angular2/http';

let body = JSON.stringify({ 'foo': 'bar' });
let headers = new Headers({ 'Access-Control-Allow-Origin': '*' });
let options = new RequestOptions({ headers: headers });

return this.http.post(url, body, options)
                .map(res =>  res.json().data)
                .catch(this.handleError)

从nuget安装using ClosedXML.Excel; dll。

以下是代码:

ClosedXML.Excel