Skip to content

Commit d96f43d

Browse files
monster910mportuga
authored andcommitted
fix(exporter.js): Eliminate selection column. Add export scale factor for excel and fonts
* fix(Export): Eliminate selection column. Add export scale factor for excel and fonts * fix(Excel Export): Add doc to show in API manual * docs(Excel export): Better doc for export to excel methods * doc(Excel export): Fix unit tests for new api doc * doc(Excel export): Fix unit tests for new api doc
1 parent 651f307 commit d96f43d

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-3
lines changed

src/features/exporter/js/exporter.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,24 @@
242242
* <br/>Defaults to 'download.pdf'
243243
*/
244244
gridOptions.exporterPdfFilename = gridOptions.exporterPdfFilename ? gridOptions.exporterPdfFilename : 'download.pdf';
245+
/**
246+
* @ngdoc object
247+
* @name exporterExcelFilename
248+
* @propertyOf ui.grid.exporter.api:GridOptions
249+
* @description The default filename to use when saving the downloaded excel, only used in IE (other browsers open excels in a new window)
250+
* <br/>Defaults to 'download.xlsx'
251+
*/
252+
gridOptions.exporterExcelFilename = gridOptions.exporterExcelFilename ? gridOptions.exporterExcelFilename : 'download.xlsx';
253+
254+
/**
255+
* @ngdoc object
256+
* @name exporterExcelSheetName
257+
* @propertyOf ui.grid.exporter.api:GridOptions
258+
* @description The default sheetname to use when saving the downloaded to excel
259+
* <br/>Defaults to 'Sheet1'
260+
*/
261+
gridOptions.exporterExcelSheetName = gridOptions.exporterExcelSheetName ? gridOptions.exporterExcelSheetName : 'Sheet1';
262+
245263
/**
246264
* @ngdoc object
247265
* @name exporterOlderExcelCompatibility
@@ -560,6 +578,66 @@
560578
*/
561579
gridOptions.exporterFieldFormatCallback = gridOptions.exporterFieldFormatCallback ? gridOptions.exporterFieldFormatCallback : function( grid, row, col, value ) { return null; };
562580

581+
/**
582+
* @ngdoc function
583+
* @name exporterExcelCustomFormatters
584+
* @propertyOf ui.grid.exporter.api:GridOptions
585+
* @description A function to call to setup formatters and store on docDefinition.
586+
*
587+
* The method is called at the start and can setup all the formatters to export to excel
588+
*
589+
* @param {Grid} grid provides the grid in case you have need of it
590+
* @param {Workbook} row the row from which the data comes
591+
* @param {docDefinition} The docDefinition that will have styles as a object to store formatters
592+
* @returns {docDefinition} Updated docDefinition with formatter styles
593+
*
594+
* @example
595+
* <pre>
596+
* gridOptions.exporterExcelCustomFormatters = function(grid, workbook, docDefinition) {
597+
* const formatters = {};
598+
* const stylesheet = workbook.getStyleSheet();
599+
* const headerFormatDefn = {
600+
* 'font': { 'size': 11, 'fontName': 'Calibri', 'bold': true },
601+
* 'alignment': { 'wrapText': false }
602+
* };
603+
*
604+
* formatters['header'] = headerFormatter;
605+
* Object.assign(docDefinition.styles , formatters);
606+
* grid.docDefinition = docDefinition;
607+
* return docDefinition;
608+
* }
609+
* </pre>
610+
*/
611+
gridOptions.exporterExcelCustomFormatters = gridOptions.exporterExcelCustomFormatters ? gridOptions.exporterExcelCustomFormatters : function( grid, workbook, docDefinition ) { return null; };
612+
613+
/**
614+
* @ngdoc function
615+
* @name exporterExcelHeader
616+
* @propertyOf ui.grid.exporter.api:GridOptions
617+
* @description A function to write formatted header data to sheet.
618+
*
619+
* The method is called to provide custom header building for Excel. This data comes before the grid header
620+
*
621+
* @param {grid} grid provides the grid in case you have need of it
622+
* @param {Workbook} row the row from which the data comes
623+
* @param {Sheet} the sheet to insert data
624+
* @param {docDefinition} The docDefinition that will have styles as a object to store formatters
625+
* @returns {docDefinition} Updated docDefinition with formatter styles
626+
*
627+
* @example
628+
* <pre>
629+
* gridOptions.exporterExcelCustomFormatters = function (grid, workbook, sheet, docDefinition) {
630+
* const headerFormatter = docDefinition.styles['header'];
631+
* let cols = [];
632+
* // push data in A1 cell with metadata formatter
633+
* cols.push({ value: 'Summary Report', metadata: {style: headerFormatter.id} });
634+
* sheet.data.push(cols);
635+
* }
636+
* </pre>
637+
*/
638+
gridOptions.exporterExcelHeader = gridOptions.exporterExcelHeader ? gridOptions.exporterExcelHeader : function( grid, workbook, sheet, docDefinition ) { return null; };
639+
640+
563641
/**
564642
* @ngdoc object
565643
* @name exporterColumnScaleFactor

src/features/exporter/test/exporter.spec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ describe('ui.grid.exporter', function() {
130130
exporterCsvColumnSeparator: ',',
131131
exporterCsvFilename: 'download.csv',
132132
exporterPdfFilename: 'download.pdf',
133+
exporterExcelFilename: 'download.xlsx',
134+
exporterExcelSheetName: 'Sheet1',
133135
exporterOlderExcelCompatibility: false,
134136
exporterIsExcelCompatible: false,
135137
exporterPdfDefaultStyle: {fontSize: 11},
@@ -150,10 +152,12 @@ describe('ui.grid.exporter', function() {
150152
exporterMenuExcel: true,
151153
exporterFieldCallback: jasmine.any(Function),
152154
exporterFieldFormatCallback: jasmine.any(Function),
155+
exporterExcelCustomFormatters: jasmine.any(Function),
156+
exporterExcelHeader: jasmine.any(Function),
157+
exporterColumnScaleFactor: 3.5,
153158
exporterFieldApplyFilters: false,
154159
exporterAllDataFn: null,
155160
exporterSuppressColumns: [],
156-
exporterColumnScaleFactor: 3.5,
157161
exporterMenuItemOrder: 200
158162
});
159163
});
@@ -174,6 +178,8 @@ describe('ui.grid.exporter', function() {
174178
exporterCsvColumnSeparator: ',',
175179
exporterCsvFilename: 'download.csv',
176180
exporterPdfFilename: 'download.pdf',
181+
exporterExcelFilename: 'download.xlsx',
182+
exporterExcelSheetName: 'Sheet1',
177183
exporterOlderExcelCompatibility: false,
178184
exporterIsExcelCompatible: false,
179185
exporterPdfDefaultStyle : { fontSize : 11 },
@@ -194,10 +200,12 @@ describe('ui.grid.exporter', function() {
194200
exporterMenuExcel: true,
195201
exporterFieldCallback: jasmine.any(Function),
196202
exporterFieldFormatCallback: jasmine.any(Function),
203+
exporterExcelCustomFormatters: jasmine.any(Function),
204+
exporterExcelHeader: jasmine.any(Function),
205+
exporterColumnScaleFactor: 3.5,
197206
exporterFieldApplyFilters: false,
198207
exporterAllDataFn: null,
199208
exporterSuppressColumns: [],
200-
exporterColumnScaleFactor: 3.5,
201209
exporterMenuItemOrder: 200
202210
});
203211
});
@@ -231,10 +239,10 @@ describe('ui.grid.exporter', function() {
231239
exporterMenuExcel: false,
232240
exporterFieldCallback: callback,
233241
exporterFieldFormatCallback: callback,
242+
exporterExcelCustomFormatters: callback,
234243
exporterFieldApplyFilters: false,
235244
exporterAllDataPromise: callback,
236245
exporterSuppressColumns: [ 'buttons' ],
237-
exporterExcelCustomFormatters: callback,
238246
exporterExcelFilename: 'myFile.xlsx',
239247
exporterExcelSheetName: 'Sheet1',
240248
exporterExcelHeader: 'My Header',

0 commit comments

Comments
 (0)