强烈要求将有关asp.net打印的专题置顶 yangzixp(扬子.net) ,调用Excel你试过吗?效果怎样? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 web打印无语言无关性。what's client???? 看来Csdn上没有太好的关于打印的解决方法了,相关的帖子我已经贴了3、4个了,都没解决,失望至极 以下代码是用EXCEL导出数据 1. 文件生成当前调用的页面的文件夹目录下,* 你把得把你当前页面的文件夹的权限改成可修改, 不然会出现脚本出错2. 在服务端生成.XLS后,调用一个window.open()方法,直接打开当前.XLS文件3. 调用方法: 直接调用 BindExcels(DataSet ds, String str, System.Web.UI.Page page)方法 里面有3个参数, ds 是当前你页面的DataSet 对象 str 是一个字段串数组,也就是DataSet 的例名, 如果你的 DataSet有4个列,你就得写成 String[] str = {"列1","列2","列3","列4"}; page 是你当前页的Page对象注: 这些方法,有一个却点, 就是数据量大时,很慢,这也是用EXCLE做报表的却点 -------------------------------------------- .CSusing System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Web.Security;using OWC;using System.IO;namespace EF.School.WEB.include{ public class GridToExcel: System.Web.UI.UserControl { public GridToExcel() {} private string sFilename; private string sDir; private bool CreateFile(System.Web.UI.Page page) { sDir=page.Server.MapPath(".")+"\\"; sFilename=page.Request.ServerVariables["REMOTE_ADDR"].Replace(".","")+".xls"; if(System.IO.File.Exists(sDir+sFilename)) { System.IO.File.Delete(sDir+sFilename); } return true; } private bool ExportDataSet2Excel(DataSet dsGrid, String sHeadnames,System.Web.UI.Page page) { try { SpreadsheetClass xlsheet = new SpreadsheetClass(); DataTable dtGrid=dsGrid.Tables[0]; int iRow=1; int iCol=0; //输出标题 string [] sHeadname=sHeadnames.Split(); for(int i=0;i<sHeadname.Length;i++) { xlsheet.ActiveSheet.Cells[1,i+1]=sHeadname[i]; //设置格式 //xlsheet.get_Range(xlsheet.Cells[1,1],xlsheet.Cells[1,i+1]).Font.Bold =true; //xlsheet.get_Range(xlsheet.Cells[1,1],xlsheet.Cells[1,i+1]).Font.Color="red"; } foreach(DataRow row in dtGrid.Rows) { iRow++; iCol=0; foreach(DataColumn col in dtGrid.Columns) { iCol++; xlsheet.ActiveSheet.Cells[iRow,iCol]=row[col.ColumnName].ToString(); } } if(CreateFile(page)) { // sFilename=@"c:/inetpub/wwwroot/EF.School/Web/AppraiseModule/StudentInfoInOrg/Excel/11.xls"; xlsheet.ActiveSheet.Export(sDir+sFilename,OWC.SheetExportActionEnum.ssExportActionNone); return true; } else { return false; } } catch { return false; } } public void BindExcels(DataSet ds, String str, System.Web.UI.Page page) { if(!ExportDataSet2Excel(ds,str,page)) { PageBase error = new PageBase(); error.Alert("导出失败",page); } else { PageBase script = new PageBase(); script.ShowScript("window.open('"+sFilename+"','','Height=500,Width=700,Top=100,Left=100,edge=1,center=1,resizable=1,status=0,toolbar=1,menubar=1');",page); } } }} 经过n天的搜索试验学习,最后决定用水晶报表,在这里谢谢xhunanpp(囨囚囨図),meixiaofeng(sean) ,goody9807() 三位老兄的在线技术支持,尤其是meixiaofeng(sean)提供软件,再次深表谢意! 很简单的一个问题,关于反斜杠的作用 |zyciis| CSDN各个网站是怎么实现共享登录的,谢谢 身高与体重的对话? vss 不能调试运行的郁闷? 请哪位高手指点,谢谢了! 对路径“c:\inetpub\wwwroot\syjl\Temp\024511.jpg”的访问被拒绝。 高手救急:ASP.NET如何抓取带带参数的页面? .net 装配件问题? 网站连接服务器的连接字符串怎么写 大家谁用过asp.net调用Excel打印?出现问题请教大家。 如何给TD定位?高手来帮忙~~~急~~~
相关的帖子我已经贴了3、4个了,都没解决,失望至极
以下代码是用EXCEL导出数据
1. 文件生成当前调用的页面的文件夹目录下,* 你把得把你当前页面的文件夹的权限改成可修改, 不然会出现脚本出错
2. 在服务端生成.XLS后,调用一个window.open()方法,直接打开当前.XLS文件
3. 调用方法:
直接调用 BindExcels(DataSet ds, String str, System.Web.UI.Page page)方法
里面有3个参数,
ds 是当前你页面的DataSet 对象
str 是一个字段串数组,也就是DataSet 的例名, 如果你的 DataSet有4个列,你就得写成 String[] str = {"列1","列2","列3","列4"};
page 是你当前页的Page对象注: 这些方法,有一个却点, 就是数据量大时,很慢,这也是用EXCLE做报表的却点 ----------------------------------------
---- .CS
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using OWC;
using System.IO;namespace EF.School.WEB.include
{ public class GridToExcel: System.Web.UI.UserControl
{
public GridToExcel()
{} private string sFilename;
private string sDir;
private bool CreateFile(System.Web.UI.Page page)
{
sDir=page.Server.MapPath(".")+"\\";
sFilename=page.Request.ServerVariables["REMOTE_ADDR"].Replace(".","")+".xls";
if(System.IO.File.Exists(sDir+sFilename))
{
System.IO.File.Delete(sDir+sFilename);
}
return true;
} private bool ExportDataSet2Excel(DataSet dsGrid, String sHeadnames,System.Web.UI.Page page)
{
try
{
SpreadsheetClass xlsheet = new SpreadsheetClass();
DataTable dtGrid=dsGrid.Tables[0];
int iRow=1;
int iCol=0; //输出标题
string [] sHeadname=sHeadnames.Split();
for(int i=0;i<sHeadname.Length;i++)
{
xlsheet.ActiveSheet.Cells[1,i+1]=sHeadname[i];
//设置格式
//xlsheet.get_Range(xlsheet.Cells[1,1],xlsheet.Cells[1,i+1]).Font.Bold =true;
//xlsheet.get_Range(xlsheet.Cells[1,1],xlsheet.Cells[1,i+1]).Font.Color="red";
} foreach(DataRow row in dtGrid.Rows)
{
iRow++;
iCol=0;
foreach(DataColumn col in dtGrid.Columns)
{
iCol++;
xlsheet.ActiveSheet.Cells[iRow,iCol]=row[col.ColumnName].ToString();
}
}
if(CreateFile(page))
{
// sFilename=@"c:/inetpub/wwwroot/EF.School/Web/AppraiseModule/StudentInfoInOrg/Excel/11.xls";
xlsheet.ActiveSheet.Export(sDir+sFilename,OWC.SheetExportActionEnum.ssExportActionNone); return true;
}
else
{
return false;
}
}
catch
{
return false;
}
} public void BindExcels(DataSet ds, String str, System.Web.UI.Page page)
{
if(!ExportDataSet2Excel(ds,str,page))
{
PageBase error = new PageBase();
error.Alert("导出失败",page);
}
else
{
PageBase script = new PageBase();
script.ShowScript("window.open('"+sFilename+"','','Height=500,Width=700,Top=100,Left=100,edge=1,center=1,resizable=1,status=0,toolbar=1,menubar=1');",page);
}
}
}
}
提供软件,再次深表谢意!