..我只想打印DataGrid中的数据.格式对齐,困扰好久了,大哥们给个方案.我试过好多方法.要么把整个页面全部表单输出.全乱了..要么就是输出内容后格式乱的厉害.无法打印..哪位大哥帮忙.帮我弄弄.怎么点按纽实现打印DataGrid中的数据.打印出来效果要好的!!! 急啊...
解决方案 »
- 求助:treeview的数据绑定实例.!~ ------在线等待
- 登陆已经实现,想做个登陆成功验证后紧接着的一个进度条怎么做?
- 问个菜鸟级问题
- 如何用readxml读取xml指定数量的记录?
- 关于owc11和office2000的问题
- UseSubmitBehavior属性用来指定Button服务器控件使用客户端浏览器提交机制,还是Asp.NET回发机制。
- 请教两个用户控件的引用区别
- 一个简单的问题
- 请问关于从sqlserver中取中文数据的问题
- 在asp.net里面写treeview应用程序的时候,需要加载什么,一个object基类怎么进行继承到可以使用treeview这个类呢?
- 用.net做过wap网页的人请帮帮忙,
- 关于联动下拉列表的问题
或者用报表工具做报表.
再调用IE自带的打印工具打印
效果还行..
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid><input type="hidden" id="content" runat="server"></div>
====
cs代码:
mailbody =content.Value.Replace("⁢","<").Replace(">",">");
Response.Write(mailbody);
方法二:
<script language="javascript">
function preview()
{
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script><form id="Form1" method="post" runat="server">
<center>本部分以上不被打印</center>
<!--startprint-->
<div align="center">
<asp:DataGrid id="dgShow" runat="server" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="4">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
</div>
<!--endprint-->
<center>本部分以下不被打印</center>
<div align="center">
<input type="button" name="print" value="预览并打印" onclick="preview()">
</div>两个方法都可以,有什么不清楚的,可以给我留言,或qq:512965230
Dim excel As Excel.Application = New Excel.Application()
Dim rowIndex As Integer = 1
Dim colIndex As Integer = 0
Dim table As DataTable = GetData()
Dim col As DataColumn
Dim row As DataRow
'add workbook
excel.Application.Workbooks.Add(True)
excel.Cells(1, 1) = ArrayCommon(14).ToString
excel.Cells(1, 2) = ArrayCommon(16).ToString
excel.Cells(1, 3) = ArrayCommon(19).ToString
excel.Cells(1, 4) = ArrayCommon(20).ToString
'data exists
If intCheckNothing = 1 Then
'set activesheet
With excel.ActiveSheet
'title font
.Range(.Cells(1, 1), .Cells(1, table.Columns.Count)).Font.Bold = True
.Range(.Cells(1, 1), .Cells(table.Rows.Count + 1, table.Columns.Count)).Borders.LineStyle = 1
.Range("a1", "a1").ColumnWidth = 13
.Range("b1", "b1").ColumnWidth = 25
.Range("c1", "c1").ColumnWidth = 22
.Range("d1", "d1").ColumnWidth = 22
.Range(.Cells(1, 1), .Cells(table.Rows.Count + 1, table.Columns.Count)).HorizontalAlignment = 3
End With For Each row In table.Rows
'fill in data
rowIndex = rowIndex + 1
colIndex = 0
For Each col In table.Columns
colIndex = colIndex + 1
excel.Cells(rowIndex, colIndex) = row(col.ColumnName).ToString()
Next
Next
Else
'data doesn't exist
excel.Cells.Font.Bold = True
excel.Cells.Range("a1", "d1").Borders.LineStyle = 1
excel.Cells.ColumnWidth = 20
excel.Cells.HorizontalAlignment = 3
End If
excel.Visible = True
End Sub
// 当前对话
System.Web.HttpContext curContext = System.Web.HttpContext.Current;
// IO用于导出并返回excel文件
System.IO.StringWriter strWriter = null;
System.Web.UI.HtmlTextWriter htmlWriter = null;
if (dbg != null)
{
// 设置编码和附件格式
curContext.Response.ContentType = "application/vnd.ms-excel";
curContext.Response.ContentEncoding =System.Text.Encoding.Default;
curContext.Response.Charset = "UTF-8";
// 导出excel文件
strWriter = new System.IO.StringWriter();
htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
// 返回客户端
dbg.RenderControl(htmlWriter);
curContext.Response.Write(strWriter.ToString());
curContext.Response.End();
dbg是方法传入的一个页面DataGrid 就是需要打印的那个 ,可是 导出Excel之后出现的结果是整个页面的表单信息全部出现。而且比较乱。。我只要打印DataGrid的数据。且可是要好。可是弄不好这样的效果。。谁能帮忙?