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