导出excel正规格式,excel导入SQL,请高手指点,在线等,另+100分。
小弟做了个导出excel,在用excel导入SQL,单导出来没问题,但是把导出来的excel在导进SQL就有问题.但是新建一个excel导入SQL又没问题,问题就出在,我导出来的只一个内似与excel的工作薄,我要把工作薄转换为excel表的格式,在把excel表里的名字改成Sheet1在导就行,转换格式没什么问题,但是又要转换excel表里的表里就有点麻烦,我导出来的时候又不能改excel表里的名字。所以请高手帮忙。修改我的代码,和给段源代码都可以,或者给个导出导入excel的小项目也可以,求求大家啦!本人邮箱cwk_1106@163.com MSN: cwk_1106@hotmail.com
导出代码:
ds = new DataSet();
ds = FEGCRM.Access.AlanSheetDA.Get( " ", " ");
DataTable dt = ds.Tables[ "Alan "];
dt.Columns[ "Id "].ColumnName = "ID ";
dt.Columns[ "LotNo "].ColumnName = "订单批号 ";
dt.Columns[ "Enterprise "].ColumnName = "业 ";
StringWriter sw = new StringWriter();
GridView dv = new GridView();
dv.DataSource = dt;
dv.DataBind();
dv.AllowPaging = false;
Response.ClearContent();
Response.Charset = "GB2312 ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename=Sheet1.xls ");
// 如果设置为 GetEncoding( "GB2312 ");导出的文件将会出现乱码!!!
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/excel ";
HtmlTextWriter htw = new HtmlTextWriter(sw);
dv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
导入代码:
string strFullFileName = DateTime.Now.ToString( "yyyymmddhhmmss ") + ".xls ";
string strpath = Server.MapPath( "excelfile ") + strFullFileName;//确定一个文件名
fileup.PostedFile.SaveAs(strpath);
string mystring = "provider = microsoft.jet.oledb.4.0 ; data source = " + strpath + ";extended properties=excel 8.0 ";
OleDbConnection