3
A
回答
0
为什么你想将它转换成图像,我不确定。如果gridview有分页,你必须像这样捕获每个页面。更好的方法是将其导出为类似Excel或其他东西。这里是代码做到这一点:
using System;
using System.Data;
using System.Configuration;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class GridViewExportUtil
{
/// <summary>
///
/// </summary>
/// <param name="fileName"></param>
/// <param name="gv"></param>
public static void Export(string fileName, GridView gv)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader(
"content-disposition", string.Format("attachment; filename={0}", fileName));
HttpContext.Current.Response.ContentType = "application/ms-excel";
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// Create a table to contain the grid
Table table = new Table();
// include the gridline settings
table.GridLines = gv.GridLines;
// add the header row to the table
if (gv.HeaderRow != null)
{
GridViewExportUtil.PrepareControlForExport(gv.HeaderRow);
table.Rows.Add(gv.HeaderRow);
}
// add each of the data rows to the table
foreach (GridViewRow row in gv.Rows)
{
GridViewExportUtil.PrepareControlForExport(row);
table.Rows.Add(row);
}
// add the footer row to the table
if (gv.FooterRow != null)
{
GridViewExportUtil.PrepareControlForExport(gv.FooterRow);
table.Rows.Add(gv.FooterRow);
}
// render the table into the htmlwriter
table.RenderControl(htw);
// render the htmlwriter into the response
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
}
}
/// <summary>
/// Replace any of the contained controls with literals
/// </summary>
/// <param name="control"></param>
private static void PrepareControlForExport(Control control)
{
for (int i = 0; i < control.Controls.Count; i++)
{
Control current = control.Controls[i];
if (current is LinkButton)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as LinkButton).Text));
}
else if (current is ImageButton)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as ImageButton).AlternateText));
}
else if (current is HyperLink)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as HyperLink).Text));
}
else if (current is DropDownList)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as DropDownList).SelectedItem.Text));
}
else if (current is CheckBox)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? "True" : "False"));
}
if (current.HasControls())
{
GridViewExportUtil.PrepareControlForExport(current);
}
}
}
}
只需调用静态导出方法与XLS文件的名称和GridView控件:
GridViewExportUtil.Export("MyFile.XLS", myGridView);
1
-2
你可以使用Java小程序。检查以下网址:
Is there a way to take a screenshot using java and save it to some sort of image?
相关问题
- 1. 将GridView Matter转换为像.jpeg这样的图像文件
- 2. 将图像转换为流
- 3. 将varbinary转换为图像
- 4. 将图像转换为DrawingImage
- 5. 将图像转换为ushort?[]
- 6. 将BufferedInputStream转换为图像
- 7. 将Swf转换为图像
- 8. 将UITextView转换为图像
- 9. 将Blob转换为图像
- 10. 将Android.Graphics.Bitmap转换为图像
- 11. 将ListBoxItem转换为图像
- 12. 将HTML转换为图像
- 13. 将图像转换为Base64String
- 14. 将HtmlElement转换为图像?
- 15. 将图像转换为JSON
- 16. 将PDF转换为图像
- 17. 将ppt转换为图像
- 18. 将xls转换为图像
- 19. 将netcdf转换为图像
- 20. 将JPanel转换为图像
- 21. 将图像转换为灰度图像
- 22. 将图像URL转换为图像Android
- 23. 将PIL图像转换为VIPS图像
- 24. 将图像转换为色度图像
- 25. 将.png图像转换为.gif图像
- 26. 将base64转换为图像并在gridview中显示
- 27. 将Gridview转换为CSV
- 28. 将GridView转换为RadGrid
- 29. DevExpress,将DataGridView转换为GridView
- 30. 将字节转换为位图图像
http://stackoverflow.com/questions/2192799/html-to-image-in-javascript-or-python – rkw
您可以使用Java小程序。检查以下网址: [此处输入链接的描述] [1] [1]:http://stackoverflow.com/questions/58305/java-is-there-a-way-服用的-A-截图,使用的Java并节省,这对一些 - 排序的 – Peyman