简体   繁体   中英

Is it possible to export everything inside an ASP Panel to .DOC, .XLS

Before getting into trouble, i would like to confirm few things with you. I am working in a dashboard project which contains, lots of controls. Everything will be inserted into a single panel control. The controls will be, table, grid, image, chart, some jquery plugins.

I would like to provide export option for word, excel, pdf. Is it possible in asp.net to export the single panel which has all the controls to word document.

Tell your suggestions

If you have any dynamic client-side code then you can't do this.

There's no way of turning a portion of a document client-side into a .doc (closest you could do is a print-to-pdf which isn't as useful)

Normally you'd do something like this server side by generating the .doc with a library like aspose - but that's going to be a real pain to do yourself if you're presenting things involving jquery plugins.

To get the result you want you're likely going to have to bite on the bullet and recreate everything server-side to generate a .doc which the client can then download.

您可以使用Javascript html2Canvas来制作屏幕截图,例如,它基于页面中的信息来构建屏幕。我不确定,但是您可以将该信息发送到服务器,创建PDF,然后将其发送到浏览器(理论上至少可行)

Yep, pretty simple actually. Here is an example exporting a Gridview to Excel. You can do the same thing with any control. Instead of this.gvRequests.RenderControl, substitute your Panel control.RenderControl. Play around with it and see how it goes.

 //Export the datagrid to Excel
        System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);

        Response.AddHeader("content-disposition", "attachment; filename=SearchResults.xls");
        Response.ClearContent();


        Response.ContentType = "application/vnd.ms-excel";
        this.gvRequests.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.Flush();
        Response.End();

yes,

static public void RenderToExcel(Panel panelReport1, Panel panelReport2, Panel panelReport3, string strFileName) { HttpContext.Current.Response.Clear(); string attachment = "attachment; filename=" + strFileName + ".xls"; //HttpContext.Current.Response.AddHeader("content-disposition", attachment); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.AddHeader("content-disposition", attachment); HttpContext.Current.Response.Charset = ""; //HttpContext.Current.Response.ContentType = "application/vnd.xls";

  //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding(1252); StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); panelReport1.RenderControl(htw); if (panelReport2 != null) { panelReport2.RenderControl(htw); if (panelReport3 != null) panelReport3.RenderControl(htw); } HttpContext.Current.Response.Write(sw.ToString()); Response.End(); } 

You can use the WebBrowser control server-side in code to request your own page in server memory and generate an image that way, or use this library (easier) http://www.websitesscreenshot.com/

EDIT

After pondering this for a bit what you want is already available!

User goes to web-page, presses ALT + Print Screen, Goes to Word or Excel whatever and presses CTRL + P !!! job-done and it's all built in \\0/ go home early :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM