能用ASP.NET 结合 Excel完成Web报表打印吗?给个方案吧! 如题:要使用Excel应该引用什么控件啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://dotnet.aspx.cc/ShowDetail.aspx?id=8A4CBF47-B888-4832-3389-ED3A3A3C8AABhttp://dotnet.aspx.cc/ShowDetail.aspx?id=EC5E84EC-68F9-4CD7-9E11-6F5C92027F0B 给你个代码private void btnexcel_Click(object sender, System.EventArgs e) { Response.Clear(); Response.Buffer= true; if (Session["Language"]!=null && Session["Language"].ToString()!="EN") { Response.Charset="GB2312"; } Response.AppendHeader("Content-Disposition","attachment;filename=FileName.xls"); if (Session["Language"]!=null && Session["Language"].ToString()!="EN") { Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312"); }//设置输出流为简体中文 Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。application/ms-word || application/ms-txt || application/ms-html || 或其他浏览器可直接支持文档 this.EnableViewState = false; System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true); System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); this.dgBrowse.RenderControl(oHtmlTextWriter); //dgBrowse为DataGrid控件,也可以是动态生成的HtmlTable Response.Write(oStringWriter.ToString()); Response.End(); }用这种方法可以将DataGrid倒入到Excel,然后打印 http://dotnet.aspx.cc/ShowDetail.aspx?id=8A4CBF47-B888-4832-3389-ED3A3A3C8AABhttp://dotnet.aspx.cc/ShowDetail.aspx?id=EC5E84EC-68F9-4CD7-9E11-6F5C92027F0B 我的意思是:打开一个Excel文件,按照自己的意愿将数据写入该文件。这样可以对付复杂的报表。在应用程序中使用过,效果很好。在Web下该怎么办呢???!!! Excel.Application oExcel;Excel.WorkBook oBook;Object oMissing=System.Reflection.Missing.Value;oExcel=new Excel.Application();oBook=oExcel.WorkBooks.Add(oMissing);for(int i=1;i<=4;i++){oExcel.Cells[i,1]=i.ToString();oExcel.Cells[i,2]="'bbb2";oExcel.Cells[i,3]="'ccc3";oExcel.Cells[i,4]="'ddd4";}oBook.Saved=true;oExcel.UserControl=false;string mm=Server.MapPath(".")+"\\aa.xls";oExcel.ActiveWorkbook.SaveCopyAs(mm);oExcel.Quit();Reponse.Redirect("aa.xls");笔记上的,忘了在哪看的了,xls文件也可以不发回给用户,而通过调用sharepoint直接在客户机上运行office程序打开服务器上的xls文件,然后编辑保存打印都可以。 GirdView事件问题 浏览器的开发步骤 ASP.NET MVC可以定制三层路径吗? 报表? 怎么在点击编辑按钮的时候给datagrid添加一个textbox 急啊!!!关于HtmlTextArea的问题?? 如何将类型为varchar 的值转换为类型为int的值 dataTable中创建新的dataTable 我在CS文件里得到一个Mydatareader 如何在Html里取的值 大家用什么编辑软件编辑asp.net网页阿? ASP.NET中如何得到硬盘的序列号的引用问题? web.config的问题?????急
private void btnexcel_Click(object sender, System.EventArgs e)
{
Response.Clear();
Response.Buffer= true;
if (Session["Language"]!=null && Session["Language"].ToString()!="EN")
{
Response.Charset="GB2312";
}
Response.AppendHeader("Content-Disposition","attachment;filename=FileName.xls");
if (Session["Language"]!=null && Session["Language"].ToString()!="EN")
{
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
}//设置输出流为简体中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
application/ms-word || application/ms-txt || application/ms-html || 或其他浏览器可直接支持文档
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.dgBrowse.RenderControl(oHtmlTextWriter);
//dgBrowse为DataGrid控件,也可以是动态生成的HtmlTable
Response.Write(oStringWriter.ToString());
Response.End();
}
用这种方法可以将DataGrid倒入到Excel,然后打印
在应用程序中使用过,效果很好。在Web下该怎么办呢???!!!
Excel.WorkBook oBook;
Object oMissing=System.Reflection.Missing.Value;
oExcel=new Excel.Application();
oBook=oExcel.WorkBooks.Add(oMissing);
for(int i=1;i<=4;i++)
{
oExcel.Cells[i,1]=i.ToString();
oExcel.Cells[i,2]="'bbb2";
oExcel.Cells[i,3]="'ccc3";
oExcel.Cells[i,4]="'ddd4";
}
oBook.Saved=true;
oExcel.UserControl=false;
string mm=Server.MapPath(".")+"\\aa.xls";
oExcel.ActiveWorkbook.SaveCopyAs(mm);
oExcel.Quit();
Reponse.Redirect("aa.xls");笔记上的,忘了在哪看的了,xls文件也可以不发回给用户,而通过调用sharepoint直接在客户机上运行office程序打开服务器上的xls文件,然后编辑保存打印都可以。