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(); }
public static WorkbookNode ExportToSpreadSheet(this DataView view, string worksheetName, DataViewExportOptions options) { ExceptionHelper.FalseThrow<ArgumentNullException>(view != null, "view"); ExceptionHelper.CheckStringIsNullOrEmpty(worksheetName, "worksheetName"); ExceptionHelper.FalseThrow<ArgumentNullException>(options != null, "options"); WorkbookNode workbook = new WorkbookNode(); InitStyles(workbook); workbook.Worksheets.Add(BuildWorkSheet(worksheetName, view, options)); return workbook; }
public static void FillIntoSpreadSheet(this DataView view, WorkbookNode workbook, string worksheetName, DataViewExportOptions options) { ExceptionHelper.FalseThrow<ArgumentNullException>(view != null, "view"); ExceptionHelper.FalseThrow<ArgumentNullException>(workbook != null, "workbook"); ExceptionHelper.CheckStringIsNullOrEmpty(worksheetName, "worksheetName"); ExceptionHelper.FalseThrow<ArgumentNullException>(options != null, "options"); InitStyles(workbook); ExceptionHelper.FalseThrow(workbook.Worksheets.Contains(worksheetName), "不能找到名称为{0}的Worksheet", worksheetName); WorksheetNode worksheet = workbook.Worksheets[worksheetName]; FillIntoWorksheet(worksheet, view, options); }
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(); }
private static void FillIntoWorksheet(WorksheetNode worksheet, DataView view, DataViewExportOptions options) { foreach (DataColumn column in view.Table.Columns) { if (options.IgnoredColumnNames.Exists(c => c == column.ColumnName) == false) { ColumnNode columnNode = new ColumnNode(); columnNode.Caption = column.ColumnName; options.OnDateViewExportColumnHeader(column, columnNode, options.Context); worksheet.Table.Columns.Add(columnNode); } } bool isFirstRow = true; if (options.ExportColumnHeader) { RowNode rowNode = BuildHeaderRow(view.Table.Columns); if (options.StartRow > 0) rowNode.Index = options.StartRow; worksheet.Table.Rows.Add(rowNode); isFirstRow = false; } foreach (DataRowView drv in view) { RowNode rowNode = new RowNode(); if (isFirstRow) { if (options.StartRow > 0) rowNode.Index = options.StartRow; isFirstRow = false; } bool isFirstColumn = true; foreach (DataColumn column in view.Table.Columns) { if (options.IgnoredColumnNames.Exists(c => c == column.ColumnName) == false) { CellNode cellNode = new CellNode(); cellNode.Data.Type = GetCellDataType(column); object dataValue = drv[column.ColumnName]; if (dataValue != null) { if (cellNode.Data.Type == CellDataType.DateTime && (dataValue is DateTime)) { cellNode.Data.Value = string.Format("{0:yyyy-MM-ddTHH:mm:ss}", dataValue); cellNode.StyleID = "NormalDateTime"; } else cellNode.Data.Value = dataValue.ToString(); } if (isFirstColumn) { if (options.StartColumn > 0) cellNode.Index = options.StartColumn; isFirstColumn = false; } options.OnDateViewExportColumnData(column, cellNode, dataValue, options.Context); rowNode.Cells.Add(cellNode); } } worksheet.Table.Rows.Add(rowNode); } }
public static void FillIntoSpreadSheet(this DataView view, WorkbookNode workbook, string worksheetName) { DataViewExportOptions options = new DataViewExportOptions(); FillIntoSpreadSheet(view, workbook, worksheetName, options); }
private static WorksheetNode BuildWorkSheet(string name, DataView view, DataViewExportOptions options) { WorksheetNode worksheet = new WorksheetNode(); worksheet.Name = name; FillIntoWorksheet(worksheet, view, options); return worksheet; }
public static WorkbookNode ExportToSpreadSheet(this DataView view, string worksheetName) { DataViewExportOptions options = new DataViewExportOptions(); return ExportToSpreadSheet(view, worksheetName, options); }