-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Excel export with npm instructions, fix error on menu and more exampl…
…es (#6506) * Initial checkin of export to excel. No examples or unit tests * Eliminate $$hashKey and uidPrefix = 'uiGrid' from export * Sheet name cannot be empty string or it causes export errors. Default to 'Sheet1' * Additional languages * Add documentation * fix syntax causing lint errors. Check if not a tree when exporting to prevent error * Updated example with colors * Update unit tests and fix the lodash version for import to remove ambiguity. * Update comments * Fix menu under strict mode from throwing error * Updated directions for npm and add more formatting examples * Fix test cases for excel export that was a merge error
- Loading branch information
1 parent
88f5525
commit bc37cb4
Showing
3 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,11 @@ available through: | |
<pre> bower install lodash | ||
bower install jszip#2.6.1 | ||
bower install excelbuilder </pre> | ||
or | ||
|
||
<pre> npm install lodash | ||
npm install [email protected] | ||
npm install excel-builder </pre> | ||
|
||
The options and API for exporter can be found at {@link api/ui.grid.exporter ui.grid.exporter}, and | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,13 @@ available through: | |
bower install jszip#2.6.1 | ||
bower install excelbuilder </pre> | ||
|
||
or | ||
|
||
<pre> npm install lodash | ||
npm install [email protected] | ||
npm install excel-builder </pre> | ||
|
||
|
||
The options and API for exporter can be found at {@link api/ui.grid.exporter ui.grid.exporter}, and | ||
|
||
- {@link api/ui.grid.exporter.api:ColumnDef columnDef} | ||
|
@@ -48,7 +55,9 @@ In this example we use the native grid menu buttons, and we show the pdf, csv an | |
columnDefs: [ | ||
{ field: 'name' }, | ||
{ field: 'gender', visible: false}, | ||
{ field: 'company' } | ||
{ field: 'company' }, | ||
{ field: 'member' }, | ||
{ field: 'total' } | ||
], | ||
enableGridMenu: true, | ||
enableSelectAll: true, | ||
|
@@ -74,19 +83,29 @@ In this example we use the native grid menu buttons, and we show the pdf, csv an | |
exporterExcelCustomFormatters: function ( grid, workbook, docDefinition ) { | ||
|
||
var stylesheet = workbook.getStyleSheet(); | ||
var stdStyle = stylesheet.createFontStyle({ | ||
size: 9, fontName: 'Calibri' | ||
}); | ||
var boldStyle = stylesheet.createFontStyle({ | ||
size: 9, fontName: 'Calibri', bold: true | ||
}); | ||
var aFormatDefn = { | ||
"font": { "size": 9, "fontName": "Calibri", "bold": true }, | ||
"font": boldStyle.id, | ||
"alignment": { "wrapText": true } | ||
}; | ||
var formatter = stylesheet.createFormat(aFormatDefn); | ||
// save the formatter | ||
$scope.formatters['bold'] = formatter; | ||
|
||
aFormatDefn = { | ||
"font": { "size": 9, "fontName": "Calibri" }, | ||
"font": stdStyle.id, | ||
"fill": { "type": "pattern", "patternType": "solid", "fgColor": "FFFFC7CE" }, | ||
"alignment": { "wrapText": true } | ||
}; | ||
var singleDefn = { | ||
font: stdStyle.id, | ||
format: '#,##0.0' | ||
}; | ||
formatter = stylesheet.createFormat(aFormatDefn); | ||
// save the formatter | ||
$scope.formatters['red'] = formatter; | ||
|
@@ -99,22 +118,25 @@ In this example we use the native grid menu buttons, and we show the pdf, csv an | |
// this can be defined outside this method | ||
var stylesheet = workbook.getStyleSheet(); | ||
var aFormatDefn = { | ||
"font": { "size": 9, "fontName": "Calibri", "bold": true }, | ||
"alignment": { "wrapText": true } | ||
}; | ||
"font": { "size": 11, "fontName": "Calibri", "bold": true }, | ||
"alignment": { "wrapText": true } | ||
}; | ||
var formatterId = stylesheet.createFormat(aFormatDefn); | ||
|
||
// excel cells start with A1 which is upper left corner | ||
sheet.mergeCells('B1', 'C1'); | ||
var cols = []; | ||
// push empty data | ||
cols.push({ value: '' }); | ||
// push data in B1 cell with metadata formatter | ||
cols.push({ value: 'My header that is long enough to wrap', metadata: {style: formatterId.id} }); | ||
sheet.data.push(cols); | ||
}, | ||
exporterFieldFormatCallback: function(grid, row, gridCol, cellValue) { | ||
// set metadata on export data to set format id. See exportExcelHeader config above for example of creating | ||
// a formatter and obtaining the id | ||
var formatterId = null; | ||
if (cellValue && cellValue.startsWith('W')) { | ||
if (cellValue && typeof cellValue === 'string' && cellValue.startsWith('W')) { | ||
formatterId = $scope.formatters['red'].id; | ||
} | ||
|
||
|
@@ -131,6 +153,10 @@ In this example we use the native grid menu buttons, and we show the pdf, csv an | |
|
||
$http.get('/data/100.json') | ||
.success(function(data) { | ||
for (var i=0; i < data.length; i++) { | ||
data[i].member = false; | ||
data[i].total = i + 0.1; | ||
} | ||
$scope.gridOptions.data = data; | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters