日期:2014-05-18  浏览次数:20702 次

怎样读取excel到dataGridView中?
如题。。
为什么我的电脑就不可以用
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + filePath + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";//HDR=YES 有两个值:YES/NO,表示第一行是否字段名,默认是YES,第一行是字段名
OleDbConnection conn = new OleDbConnection(strConn);
呢?
好纠结、、、

求一简单的读取excel方法

------解决方案--------------------
private void ExportDataGrid(string FileType, string FileName)
{
Response.Charset = "UTF8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8));
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.dgvOrgUnit.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}