// Save the data in the Table control to Excel or Word
Public void save (system.web.ui.control source, documenttype type)
{Response.clear (); response.buffer = true;
// Set the header information of HTTP, encoding format if (type == DocumentType.excel) {// Excel Response.Appendheader ("Content-Disposition", "Attachment; FileName = Result.xls"); response.contentType = "Application / MS-Excel ";} else if (type == DocumentType.Word) {// Word Response.Appendheader (" Content-Disposition "," Attachment; FileName = Result.doc "); response.contenttype =" Application / MS -Word ";
// Set the encoded response.charset = "gb2312"; response.contentencoding = system.text.Encoding.Getencoding ("GB2312");
// Close the view status of the control Source.enableViewState = FALSE;
// Initialization HtmlWriter System.IO.StringWriter writer = new System.IO.StringWriter (); System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter (writer); source.RenderControl (htmlWriter);
// Output Response.write (Writer.toString ());
Response.end ();
Public enum documenttype {word, excel}
When the data is saved when the data is saved, you need to create an inconspicuous object and then resold the data and save the data. Otherwise, the button is not saved because it is not the client's control.
// The following is saving picture public void savePic () {string path = server.mappath (".") @ "/ Images / chart.jpeg"; filestream file = file.openread (path); byte [] content = new Byte [file.Length]; file.read (content, 0, content.length); file.close ();
Response.Clear (); response.Appendheader ("Content-Disposition", "Attachment; FileName = chart.jpeg"); response.contentType = "image / jpeg"; // Set the HTTP header information response.binaryWrite (Content) ; // Output response.end ();
However, after the picture is saved, the DropDownload's SELECT event on the page cannot promote. I don't know what is the reason, but the Button event on the page can inspire the event. I don't know if you have this problem. Can you discuss it or have a problem with the process I saved? Comments
#
Reply: Save the data output in the control to local Excel or Word while saving the picture to the local (C #)
2004-09-16 10:01 AM
Wood
Supplement: When downloading the attachment to the client, since the page is used in the case, it will cause the control of the DropDownList if the page will make the incident, the income is incorrectly prompt, but Button can be due to multiple web portfolios. It is interfered together, there is currently no solution, so if you use the controls such as DropDownList, you can only download attachments in a single page (ie, the page is not Frame).
#
Reply: Save the data output in the control to local Excel or Word while saving the picture to the local (C #)
2004-09-16 11:02 AM
Wood
Change Attachment to ONLINE to open Word Excel online.