乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > ASP.NET实现EXCEL表的导入有没有控件用的?-asp.net导出excel 组件,asp导出excel的方法

ASP.NET实现EXCEL表的导入有没有控件用的?-asp.net导出excel 组件,asp导出excel的方法

作者:乔山办公网日期:

返回目录:excel表格制作


public static DataTable ExcelToDataTable(string strExcelFileName, string strSheetName)
        {
            //源的定义
            string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + strExcelFileName + ";" + "Extended Properties='Excel 8.0;HDR=NO;IMEX=1';";
            
            //Sql语句e68a84e8a2ade799bee5baa6e79fa5e98193362
            //string strExcel = string.Format("select * from [{0}$]", strSheetName); 这是一种方法
            string strExcel = "select * from  [" + strSheetName+"]";//[sheet1$]

            //定义存放的数据表
            DataSet ds = new DataSet();

            //连接数据源
            OleDbConnection conn = new OleDbConnection(strConn);

            conn.Open();

            //适配到数据源
            OleDbDataAdapter adapter = new OleDbDataAdapter(strExcel, strConn);
            adapter.Fill(ds, strSheetName);

            conn.Close();

            return ds.Tables[strSheetName];
        }


读取excel的代码,http://codeo.cn



DataSetToLocalExcelpublic static void DataSetToLocalExcel(DataSet dataSet, string outputPath, bool deleteOldFile)    {      if (deleteOldFile)      {        if (System.IO.File.Exists(outputPath)) { System.IO.File.Delete(outputPath); }      }      // Create the Excel Application object      ApplicationClass excelApp = new ApplicationClass();        // Create a new Excel Workbook      Workbook excelWorkbook = excelApp.Workbooks.Awww.cqzol.com看看 7a64e4b893e5b19e363
好像不太简单,不过可以读出数据来自己添加样式。

这个有很多种方式,引用。com 组件中的关于Office的DLL 能实现。也可以使用第三方的dll 推荐NPOI 比较简单,至于教程NPOI网上的很多

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网