我正在做一個asp.net項目從頁面打印Devexpress網格?
我使用的是Devexpress gridview 9.1。
我想打印gridview只有一個按鈕點擊。 基本上沒有其他控件應該在頁面上打印。
我發現,這可以通過將網格傳遞到下一頁並將其打印在那裏。 但我的要求不允許。
所以有可能通過任何方式在同一頁面上單獨打印gridview?
我正在做一個asp.net項目從頁面打印Devexpress網格?
我使用的是Devexpress gridview 9.1。
我想打印gridview只有一個按鈕點擊。 基本上沒有其他控件應該在頁面上打印。
我發現,這可以通過將網格傳遞到下一頁並將其打印在那裏。 但我的要求不允許。
所以有可能通過任何方式在同一頁面上單獨打印gridview?
使用stanalone ASPxGridViewExporter組件用於此目的:
http://demos.devexpress.com/ASPxGridViewDemos/Exporting/Exporting.aspx
protected void ASPxButton1_Click(object sender, EventArgs e)
{
using(MemoryStream ms = new MemoryStream()){
PrintableComponentLink pcl = new PrintableComponentLink(new PrintingSystem());
pcl.Component = ASPxGridViewExporter1;
pcl.Margins.Left = pcl.Margins.Right = 50;
pcl.Landscape = true;
pcl.CreateDocument(false);
pcl.PrintingSystem.Document.AutoFitToPagesWidth = 1;
pcl.ExportToPdf(ms);
WriteResponse(this.Response, ms.ToArray(), System.Net.Mime.DispositionTypeNames.Inline.ToString());
}
}
public static void WriteResponse(HttpResponse response, byte[] filearray, string type)
{
response.ClearContent();
response.Buffer = true;
response.Cache.SetCacheability(HttpCacheability.Private);
response.ContentType = "application/pdf";
ContentDisposition contentDisposition = new ContentDisposition();
contentDisposition.FileName = "test.pdf";
contentDisposition.DispositionType = type;
response.AddHeader("Content-Disposition", contentDisposition.ToString());
response.BinaryWrite(filearray);
HttpContext.Current.ApplicationInstance.CompleteRequest();
try
{
response.End();
}
catch (System.Threading.ThreadAbortException)
{
}
}
如果我理解正確的話,導出爲PDF/Excel是不能接受的? – Filip