c#数据导入到excel2007出错,2003打开可以
Response.Clear()Response.Buffer = True
Response.Charset = "BIG5"
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls")
Response.ContentEncoding = System.Text.Encoding.UTF7
Response.ContentType = "application/ms-excel"
Dim sw As New System.IO.StringWriter()
Dim htw As New System.Web.UI.HtmlTextWriter(sw)
Me.gridview1.RenderControl(htw)
Response.Output.Write(sw)
Response.Flush()
Response.End() --------------------编程问答-------------------- 不支持 微软只支持03的呢 那个格式代码不认识 --------------------编程问答-------------------- 把 Response.ContentEncoding = System.Text.Encoding.UTF7
改为
Response.ContentEncoding = System.Text.Encoding.UTF-8 --------------------编程问答-------------------- 貌似这种方式只能支持03格式的,不支持07格式的! --------------------编程问答-------------------- public void openExcel()
{
OpenFileDialog openf = new OpenFileDialog();//打开文件
// Stream myStream;
string excelFile = "";
if (openf.ShowDialog() == DialogResult.OK)
{
excelFile = Convert.ToString(openf.FileName);//如果打开后将路径赋值给excelFile
}
DataSet ds = new DataSet();
System.Data.DataTable tb1 = new System.Data.DataTable();
string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Extended Properties=Excel 12.0;" +
"data source=" + excelFile;
// 查询语句
string sql =string.Format( "SELECT * FROM [{0}]",tableName);
OleDbDataAdapter da = new OleDbDataAdapter(sql, connStr);
// SqlDataAdapter da = new SqlDataAdapter(sql,connStr);
da.Fill(tb1); // 填充DataSet
// dataGridView1.DataSource = tb1;//
ds.Tables.Add(tb1);
return ds;
}
补充:.NET技术 , C#