我在我的网站中使用 Ignite UI 来查看表格,我需要将其导出到 Excel。我正在使用默认的 Infragistricts 功能 $.ig.GridExcelExporter.exportGrid
,但我得到的表格只有标题的下部。我有多列标题,我只得到下部。有没有办法解决它?
最佳答案
igGridExcelExporter 不处理 MultiColumnHeaders。此外,网格被导出到工作表内的表格区域,不允许单元格合并。这意味着您可以通过在 exportEnding 事件中插入新行并合并单元格来模仿多标题:
exportEnding: function(sender, args) {
args.worksheet.rows().insert(0, 1); // insert one new row at index 0
//create a merged cells region that will act as a multi header
var mergedHeaderRegion = args.worksheet.mergedCellsRegions().add(0,1,0,2); // firstRowIndex, firstColumnIndex, lastRowIndex, lastColumnIndex
mergedHeaderRegion.value("Month1");
// style the newly inserted row as a header
for (var columnIndex = 0; columnIndex < 4; columnIndex++) {
args.worksheet.rows(0).getCellFormat(columnIndex).fill($.ig.excel.CellFill.createSolidFill("rgb(136, 136, 136)"));
args.worksheet.rows(0).getCellFormat(columnIndex).font().colorInfo(new $.ig.excel.WorkbookColorInfo("rgb(255, 255, 255)")); }
}
您还可以引用以下帮助主题和 API 文档:
http://www.igniteui.com/help/javascript-excel-library-merge-cells
http://help.infragistics.com/jQuery/2015.2/
关于excel - 使用多列标题将 UI 导出到 Excel 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36541932/