NPOI开发中遇到的问题
读取excel数据:找不到可安装的ISAM
错误:
string strConn = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Dir + "\\"+fileName + ";Extended Properties=Excel 8.0;HDR=Yes;IMEX=1;";
正确改为:
string strConn = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Dir + "\\"+fileName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
NPOI 读取Excel中的数据时出现了只能读表格前几行有数据的列,前几行没有数据的列就读不到,除非在前一行所有的单元格都填充数据。
public static DataSet LoadDataFromExcel(string filePath)
{
try
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0'";
OleDbConnection OleConn = new OleDbConnection(strConn);
OleConn.Open();
String sql = "SELECT * FROM [Sheet1$]";//可是更改Sheet名称,比如sheet2,等等
OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn);
DataSet ds = new DataSet();
OleDaExcel.Fill(ds,"Sheet");
OleConn.Close();
return ds;
}
catch (Exception err)
{
MessageBox.Show("数据绑定Excel失败!失败原因:" + err.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return null;
}
}

改正:
将 string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0'";
改为:string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'";
浙公网安备 33010602011771号