datagrid打印问题,包括分页较多时怎么打印,能不能输出到word打印,100分 RT 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //==========================================css可以控制一些//==========================================http://blog.csdn.net/net_lover/archive/2004/07/06/35228.aspx//==================================================将DATAGRID放到DIV层中通过打印DIV层来打印DATAGRID的例子//========================================================<input id="BtnPrint" onclick="printpage()" type="image" alt="印刷" src="IMG\btnPrintOriko.gif"><div id="printdiv"><asp:datagrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 6px; POSITION: absolute; TOP: 94px" runat="server" Width="2700px"> <SelectedItemStyle BackColor="#FF0066"></SelectedItemStyle> <AlternatingItemStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="#33CCFF"></AlternatingItemStyle> <ItemStyle HorizontalAlign="Center" Width="100%" VerticalAlign="Middle" BackColor="#66CC99"></ItemStyle> <HeaderStyle HorizontalAlign="Center" Width="100%" VerticalAlign="Middle" BackColor="#FF9966"></HeaderStyle> </asp:datagrid></div><script language="javascript"> function printpage() { var aaa = document.all.printdiv.innerHTML; var printOpen printOpen=window.open('printForm.aspx','open1','width=600,height=390,top=100,left=100'); printOpen.document.body.innerHTML = aaa; printOpen.window.print(document.Print); printOpen.close(); } </script>都是在HTML的页上的代码通过测试好用:) webform打印,不是winform打印啊,刚才忘说了,楼上的我看看 你可以dataset 导入 excel参考http://community.csdn.net/Expert/topic/3077/3077526.xml?temp=.8746912http://www.dev-club.com/club/bbs/showEssence.asp?id=26350http://dev.csdn.net/Develop/article/18/18623.shtmhttp://community.csdn.net/Expert/topic/3112/3112296.xml?temp=.926861http://dotnet.aspx.cc/ShowDetail.aspx?id=BF0A54F9-C7C7-4200-BD9A-802AC1F5DE50http://expert.csdn.net/Expert/TopicView1.asp?id=2928057www.foxhis.com/powermjtest/原文代码:private void Button1_Click(object sender, System.EventArgs e){ //写入Excel的方法: //定义需要参数。 string SourceFile="Data.XLS"; //源文件名称。 string TemplatePath=Server.MapPath("ExcelTemplate"); //存放源文件的文件夹路径。 string DownloadPath=Server.MapPath("ExcelDownload"); //副本的文件夹路径。 //副本的文件名。 string TempFileName = DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".XLS"; object missing = System.Reflection.Missing.Value; Excel.Application myExcel=new Excel.Application(); //打开新文件 myExcel.Application.Workbooks.Open(TemplatePath+"\\"+SourceFile,missing,missing,missing,missing, missing,missing,missing,missing,missing,missing, missing,missing); Excel.Workbook myBook=myExcel.Workbooks[1]; Excel.Worksheet curSheet = (Excel.Worksheet)myBook.Sheets[2]; string DownloadFilePath=DownloadPath+"\\"+TempFileName; int i=0; while (i<=10) { myExcel.Cells[4+i,2]=i.ToString(); myExcel.Cells[4+i,3]=i.ToString(); myExcel.Cells[4+i,4]=i.ToString(); myExcel.Cells[4+i,5]=i.ToString(); myExcel.Cells[4+i,6]=i.ToString(); i++; } myBook.Saved=true; //myBook.SaveAs(DownloadFilePath,missing,"","",false,false,Excel.XlSaveAsAccessMode.xlNoChange,1,false,missing,missing); myBook.PrintPreview(0); //myBook.PrintOut(missing,missing,missing,missing,missing,missing,missing,missing); myBook.Close(false, null,null); myExcel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(myBook); System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel); myBook = null; myExcel = null; GC.Collect(); //Response.Redirect("ExcelDownload//"+TempFileName); //下载文件} http://dotnet.aspx.cc/ShowDetail.aspx?id=8A4CBF47-B888-4832-3389-ED3A3A3C8AAB 带星的高手们,导入EXCEL早就有了,有导入到WORD和PDF的吗?我加200分 我也在找,这是刚刚在CSDN记录中搜索,可以导入Excel和Word,不知道如何导入Pdf。在某个button事件中添加: 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";//设置设置输出文件类型 //可以是 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); DataGrid1.RenderControl(oHtmlTextWriter); //DataGrid1为DataGrid控件,也可以是动态生成的HtmlTable <---唯一需要修改的地方 Response.Write(oStringWriter.ToString()); Response.End(); 不好意思,有分了再给kes2000(云之雾) goody9807() SWFUpload 获取图片路径的问题 如何通过后台向ListBox中添加自定义的项? OnClientClick后OnClick不执行 跪求解决阿 用.net调用曼特斯自动计算邮资的问题 关于存储过程的问题,谢谢大家 GridView行点击事件...急啊.. 如何在火狐浏览器上实现alt标签的效果? VS中进行页面调试运行时出错 乱码问题 请文这个功能该如何实现 求asp.net菜单(自定义控件dll)源码,急谢谢,分不够还可以加 VS.NET怎么才能通过硬盘安装?
css可以控制一些
//==========================================
http://blog.csdn.net/net_lover/archive/2004/07/06/35228.aspx
//==================================================
将DATAGRID放到DIV层中
通过打印DIV层来打印DATAGRID的例子
//========================================================
<input id="BtnPrint" onclick="printpage()" type="image" alt="印刷" src="IMG\btnPrintOriko.gif"><div id="printdiv"><asp:datagrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 6px; POSITION: absolute; TOP: 94px" runat="server" Width="2700px">
<SelectedItemStyle BackColor="#FF0066"></SelectedItemStyle>
<AlternatingItemStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="#33CCFF"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Center" Width="100%" VerticalAlign="Middle" BackColor="#66CC99"></ItemStyle>
<HeaderStyle HorizontalAlign="Center" Width="100%" VerticalAlign="Middle" BackColor="#FF9966"></HeaderStyle>
</asp:datagrid></div><script language="javascript">
function printpage()
{
var aaa = document.all.printdiv.innerHTML;
var printOpen
printOpen=window.open('printForm.aspx','open1','width=600,height=390,top=100,left=100');
printOpen.document.body.innerHTML = aaa;
printOpen.window.print(document.Print);
printOpen.close();
}
</script>都是在HTML的页上的代码通过测试好用
:)
http://community.csdn.net/Expert/topic/3077/3077526.xml?temp=.8746912
http://www.dev-club.com/club/bbs/showEssence.asp?id=26350http://dev.csdn.net/Develop/article/18/18623.shtm
http://community.csdn.net/Expert/topic/3112/3112296.xml?temp=.926861
http://dotnet.aspx.cc/ShowDetail.aspx?id=BF0A54F9-C7C7-4200-BD9A-802AC1F5DE50
http://expert.csdn.net/Expert/TopicView1.asp?id=2928057www.foxhis.com/powermjtest/
原文代码:
private void Button1_Click(object sender, System.EventArgs e)
{
//写入Excel的方法:
//定义需要参数。
string SourceFile="Data.XLS"; //源文件名称。
string TemplatePath=Server.MapPath("ExcelTemplate"); //存放源文件的文件夹路径。
string DownloadPath=Server.MapPath("ExcelDownload"); //副本的文件夹路径。
//副本的文件名。
string TempFileName = DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".XLS";
object missing = System.Reflection.Missing.Value;
Excel.Application myExcel=new Excel.Application();
//打开新文件
myExcel.Application.Workbooks.Open(TemplatePath+"\\"+SourceFile,missing,missing,missing,missing,
missing,missing,missing,missing,missing,missing, missing,missing);
Excel.Workbook myBook=myExcel.Workbooks[1];
Excel.Worksheet curSheet = (Excel.Worksheet)myBook.Sheets[2];
string DownloadFilePath=DownloadPath+"\\"+TempFileName;
int i=0;
while (i<=10)
{
myExcel.Cells[4+i,2]=i.ToString();
myExcel.Cells[4+i,3]=i.ToString();
myExcel.Cells[4+i,4]=i.ToString();
myExcel.Cells[4+i,5]=i.ToString();
myExcel.Cells[4+i,6]=i.ToString();
i++;
}
myBook.Saved=true;
//myBook.SaveAs(DownloadFilePath,missing,"","",false,false,Excel.XlSaveAsAccessMode.xlNoChange,1,false,missing,missing);
myBook.PrintPreview(0);
//myBook.PrintOut(missing,missing,missing,missing,missing,missing,missing,missing);
myBook.Close(false, null,null);
myExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(myBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);
myBook = null;
myExcel = null;
GC.Collect();
//Response.Redirect("ExcelDownload//"+TempFileName); //下载文件
}
在某个button事件中添加: 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";//设置设置输出文件类型
//可以是 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);
DataGrid1.RenderControl(oHtmlTextWriter); //DataGrid1为DataGrid控件,也可以是动态生成的HtmlTable <---唯一需要修改的地方
Response.Write(oStringWriter.ToString());
Response.End();