把excel读入DataTable

 1  private DataTable GetExcelTable(DataRow  row)
 2         {
 3
 4             string path = ConfigurationManager.AppSettings["UploadPath"].ToString();
 5             path = System.IO.Path.Combine(path, row["BB_FILE_PATH"].ToString().Replace("../", ""));
 6             string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";" + "Extended Properties=Excel 8.0;";
 7             OleDbConnection conn = new OleDbConnection(strConn);
 8             conn.Open();
 9             OleDbDataAdapter adp = new OleDbDataAdapter("Select * from [Sheet1$A1:AB1000] WHERE number is not null ", conn);
10             DataSet ds = new DataSet();
11             adp.Fill(ds, "Book1");
12             if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
13                 return ds.Tables[0];
14             return null;
15         }
时间: 2024-11-01 15:24:12

把excel读入DataTable的相关文章

Excel导入DataTable兼容2003-2012(请细心查看注释)以及 DataTable导出Excel(导出格式2003.xls)注释:需要引用NPOI

1.#region Excel导入DataTable兼容2003-2012(请细心查看注释)/// <summary> /// 读取Excel文件到DataSet中/// 注释1:2012导出如报错“ System.InvalidOperationException: 未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序.”解决:下载2007 Office system 驱动程序:数据连接组件安装http://download.microsoft.com/downl

.net读取Excel转datatable、.net读取的Excel存在合并单元格并且转成datatable

项目中经常会遇到Excel导入数据,Excel的模板会可能是存在合并单元格的,模板如下图所示 读取时需要填充合并单元格的值,转成datatable单元格值时,填充合并单元格的值,如下图所示: 合并单元格的值填充,这种格式的datatable使用SqlBulkCopy批量导入更为方便 Excel转datatable方法代码: /// <summary> /// Excel转DataTable /// </summary> /// <param name="filePa

c# excel转换为DataTable

System.Data.DataTable GetDataFromExcelByCom(bool hasTitle, string fileName) { //OpenFileDialog openFile = new OpenFileDialog(); //openFile.Filter = "Excel(*.xlsx)|*.xlsx|Excel(*.xls)|*.xls"; //openFile.InitialDirectory = Environment.GetFolderPat

NPOI导入excel为datatable (xls xlsx xlsm)

使用NPOI导入导出Excel(xls/xlsx)数据到DataTable中 http://www.cnblogs.com/songrun/p/3547738.html NPOI 2.0教程 – 自动识别Excel 2003或2007格式 http://tonyqus.sinaapp.com/archives/482 NPOI 2.0 教程 http://tonyqus.sinaapp.com/npoi2tutorial using System; using System.Collection

Excel转Datatable

using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; using System.Data; using System.Globalization; using System.IO; using System.Linq; using System.Threading; using System.Web

NPOI 读取excel到DataTable 读取隐藏列 读取公式列

处理思路: 1.打开excel 用NPOI进行读取: 2.读取第一个Sheet: 读取过程中: a.先设置相应列 不隐藏 b.读取Cell时 先判断是否的包含公式 相应代码如下: public static DataTable ReadDataFromExcelByNPOI() { DataTable dt = new DataTable(); var filePathAndName = Path.Combine(Server.MapPath("~/Content/Excel"), &

excel导入DataTable

http://www.cnblogs.com/top5/archive/2010/03/12/1684559.html --下载excel的dll http://bbs.csdn.net/topics/390271458 http://zhidao.baidu.com/link?url=c1m-oJjceP0oXP7_Hlm2EyoD9F71SVmlERMX3pPDSRgiKJxeIaoZV0xav9jxdJm04ibUB5h05k1wi8Hjl45O6q excel 导入到datatable

Excel操作--使用NPOI导入导出Excel为DataTable

1.ExcelHelper封装 1 namespace NPOI操作Excel 2 { 3 public class ExcelHelper 4 { 5 /// <summary> 6 /// DataTable转成Excel,返回一个文件流 7 /// </summary> 8 /// <param name="dataTable"></param> 9 /// <returns></returns> 10 pu

读取excel到DataTable

/// <summary>读取excel /// 默认第一行为表头,导入第一个工作表 /// </summary> /// <param name="strFileName">excel文档路径</param> /// <returns></returns> public static DataTable Import(string strFileName) { DataTable dt = new DataTab