protected void ExportExcel() { var dataView = (DataView)sqlDs.Select(new DataSourceSelectArguments()); if (dataView == null) { return; } var tableModel = Model.Table; var logicModel = Model.Logic; var dataTable = dataView.ToTable(); dataTable.TableName = tableModel.Name; var excelBytes = ExcelUtil.ConvertToExcel(dataTable); var period = String.Format("{0:dd.MM.yyyy_HH.mm.ss}", DateTime.Now); var fileName = String.Format("Data_{0}.xlsx", period); fileName = HttpUtility.UrlPathEncode(fileName); Response.Clear(); Response.Buffer = true; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", String.Format("inline;filename={0}", fileName)); Response.BinaryWrite(excelBytes); Response.End(); }
protected void btnTemplate_OnClick(object sender, EventArgs e) { var tableModel = Model.Table; var logicModel = Model.Logic; var dataTable = new DataTable(tableModel.Name); foreach (var columnModel in tableModel.Columns) { dataTable.Columns.Add(columnModel.Name); } var dataSet = new DataSet(); dataSet.Tables.Add(dataTable); var excelBytes = ExcelUtil.ConvertToExcel(dataSet); var period = String.Format("{0:dd.MM.yyyy_HH.mm.ss}", DateTime.Now); var fileName = String.Format("Template_{0}.xlsx", period); fileName = HttpUtility.UrlPathEncode(fileName); Response.Clear(); Response.Buffer = true; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", String.Format("inline;filename={0}", fileName)); Response.BinaryWrite(excelBytes); Response.End(); }
public static byte[] GetReportGridBytes(String targetType, DataSet dataSet) { if (targetType == "PDF") { using (var stream = new MemoryStream()) { var pdfDoc = new Document(); var writer = PdfWriter.GetInstance(pdfDoc, stream); pdfDoc.Open(); foreach (DataTable dataTable in dataSet.Tables) { var table = GetPdfGrid(dataTable); pdfDoc.Add(table); } pdfDoc.Close(); return(stream.ToArray()); } } if (targetType == "Excel") { return(ExcelUtil.ConvertToExcel(dataSet)); } if (targetType == "CSV") { var dataTable = dataSet.Tables.Cast <DataTable>().FirstOrDefault(); return(ExcelUtil.ConvertToCSV(dataTable)); } return(null); }