问题描述
rdlc报表导出的excel后,程序已对sheet1命名。如何自定义对sheet1命名呢
解决方案
解决方案二:
重命名Excel表名Microsoft.Office.Interop.Excel.Applicationexcel1=newMicrosoft.Office.Interop.Excel.Application();Workbookworkbook1=excel1.Workbooks.Add(true);Worksheetworksheet1=(Worksheet)workbook1.Worksheets["sheet1"或1];worksheet1.Name="工作计划表";excel1.Visible=true;
解决方案三:
我是自己编写的读写Excel方法利用List《》集合存储数据:可以灵活控制Excel格式;读写类如下:usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Web;usingSystem.Web.SessionState;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.HtmlControls;usingSystem.Text;usingSystem.IO;namespaceMyOffice.BLL{publicclassPrintManager{publicstaticvoidToExcel(System.Web.UI.Controlctl,stringstrFileName){HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+strFileName+".xls");HttpContext.Current.Response.Charset="utf-8";HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-8");//System.Text.Encoding.Default;HttpContext.Current.Response.ContentType="application/ms-excel";//设置输出流为简体中文ctl.Page.EnableViewState=false;System.Globalization.CultureInfomyCItrad=newSystem.Globalization.CultureInfo("ZH-CN",true);System.IO.StringWritertw=newSystem.IO.StringWriter();System.Web.UI.HtmlTextWriterhw=newSystem.Web.UI.HtmlTextWriter(tw);ctl.RenderControl(hw);HttpContext.Current.Response.Write(tw.ToString());HttpContext.Current.Response.End();hw.Flush();hw.Close();tw.Flush();tw.Close();}//导出到ExcelpublicstaticvoidToExcel2(System.Web.UI.Controlctl,stringstrFileName){HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+strFileName+".xls");HttpContext.Current.Response.Charset="GB2312";//"utf-8";HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//System.Text.Encoding.Default;HttpContext.Current.Response.ContentType="application/ms-excel";//设置输出流为简体中文ctl.Page.EnableViewState=false;System.Globalization.CultureInfomyCItrad=newSystem.Globalization.CultureInfo("ZH-CN",true);System.IO.StringWritertw=newSystem.IO.StringWriter();System.Web.UI.HtmlTextWriterhw=newSystem.Web.UI.HtmlTextWriter(tw);ctl.RenderControl(hw);HttpContext.Current.Response.Write(tw.ToString());HttpContext.Current.Response.End();hw.Flush();hw.Close();tw.Flush();tw.Close();}//导出到ExcelpublicstaticvoidToExcel(DataTabledt){stringsb="";foreach(DataRowdrindt.Rows){for(inti=0;i<dt.Columns.Count;i++){sb=sb+dr[i].ToString()+"t";}sb=sb+"n";}HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=myexcel.xls");HttpContext.Current.Response.Charset="UTF-8";HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.Default;HttpContext.Current.Response.ContentType="application/ms-excel";System.IO.StringWritertw=newSystem.IO.StringWriter();System.Web.UI.HtmlTextWriterhw=newSystem.Web.UI.HtmlTextWriter(tw);hw.WriteLine(sb.ToString());HttpContext.Current.Response.Write(tw.ToString());HttpContext.Current.Response.End();hw.Flush();hw.Close();tw.Flush();tw.Close();}//导出到ExcelpublicstaticvoidToExcel(stringsb){HttpContext.Current.Response.AppendHeader("Content-Disposition","inline;filename=myexcel.xls");HttpContext.Current.Response.Charset="UTF-8";HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.Default;HttpContext.Current.Response.ContentType="application/ms-excel";System.IO.StringWritertw=newSystem.IO.StringWriter();System.Web.UI.HtmlTextWriterhw=newSystem.Web.UI.HtmlTextWriter(tw);hw.WriteLine(sb.ToString());HttpContext.Current.Response.Write(tw.ToString());HttpContext.Current.Response.End();hw.Flush();hw.Close();tw.Flush();tw.Close();}}}
解决方案四:
大哥。。。list导出我找了好就了。。爱死你了!!!!
解决方案五:
遇到同样的问题,悲剧....还么找到解决办法