protected void exportDataSetByTemplateBtn_Click(object sender, EventArgs e) { XmlDocument xmlDoc = WebXmlDocumentCache.GetXmlDocument("Interco upload template.xml"); xmlDoc.PreserveWhitespace = true; WorkbookNode workbook = new WorkbookNode(); workbook.LoadXml(xmlDoc.OuterXml); DataTable table = CreateDemoDataTable(); DataViewExportOptions options = new DataViewExportOptions() { ExportColumnHeader = false }; table.DefaultView.FillIntoSpreadSheet(workbook, "Sheet1", options); Response.AppendHeader("CONTENT-DISPOSITION", string.Format("{0};filename={1}", "inline", HttpUtility.UrlEncode("test.xml"))); Response.ContentType = "text/xml"; Response.Clear(); workbook.Save(Response.OutputStream); Response.End(); }
/// <summary> /// 输出到Http的Response中。从UserSettings中读取文档类型和扩展名。 /// </summary> /// <param name="workbook">WorkbookNode对象</param> /// <param name="fileNameWithoutExt">不带扩展名的文件名</param> public static void Response(this WorkbookNode workbook, string fileNameWithoutExt) { ExceptionHelper.FalseThrow <ArgumentNullException>(workbook != null, "workbook"); HttpResponse response = HttpContext.Current.Response; response.AddExcelXmlHeader(fileNameWithoutExt); response.Clear(); workbook.Save(response.OutputStream); response.End(); }
protected void exportDataSetBtn_Click(object sender, EventArgs e) { DataTable table = CreateDemoDataTable(); DataViewExportOptions options = new DataViewExportOptions() { ExportColumnHeader = false }; WorkbookNode workbook = table.DefaultView.ExportToSpreadSheet("Default", options); Response.AppendHeader("CONTENT-DISPOSITION", string.Format("{0};filename={1}", "inline", HttpUtility.UrlEncode("test.xml"))); Response.ContentType = "text/xml"; Response.Clear(); workbook.Save(Response.OutputStream); Response.End(); }