File size: 8,377 Bytes
0936134 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Autowired, Bean, PostConstruct, _ } from '@ag-grid-community/core';
import { ExcelXmlSerializingSession } from './excelXmlSerializingSession';
import { ExcelXlsxSerializingSession } from './excelXlsxSerializingSession';
import { BaseCreator, RowType } from "@ag-grid-community/csv-export";
var ExcelCreator = /** @class */ (function (_super) {
__extends(ExcelCreator, _super);
function ExcelCreator() {
return _super !== null && _super.apply(this, arguments) || this;
}
ExcelCreator.prototype.postConstruct = function () {
this.setBeans({
downloader: this.downloader,
gridSerializer: this.gridSerializer,
gridOptionsWrapper: this.gridOptionsWrapper
});
};
ExcelCreator.prototype.exportDataAsExcel = function (params) {
this.setExportMode(params ? params.exportMode : undefined);
return this.export(params);
};
ExcelCreator.prototype.getDataAsExcelXml = function (params) {
if (params && params.exportMode) {
delete params.exportMode;
}
this.setExportMode('xml');
return this.getData(params || {});
};
ExcelCreator.prototype.getMimeType = function () {
return this.getExportMode() === 'xml' ? 'application/vnd.ms-excel' : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
};
ExcelCreator.prototype.getDefaultFileName = function () {
return "export." + this.getExportMode();
};
ExcelCreator.prototype.getDefaultFileExtension = function () {
return this.getExportMode();
};
ExcelCreator.prototype.createSerializingSession = function (params) {
var _a = this, columnController = _a.columnController, valueService = _a.valueService, gridOptionsWrapper = _a.gridOptionsWrapper;
var isXlsx = this.getExportMode() === 'xlsx';
var excelFactory = isXlsx ? this.xlsxFactory : this.excelXmlFactory;
var sheetName = 'ag-grid';
if (_.exists(params.sheetName)) {
sheetName = _.utf8_encode(params.sheetName.toString().substr(0, 31));
}
var config = __assign(__assign({}, params), { columnController: columnController,
valueService: valueService,
gridOptionsWrapper: gridOptionsWrapper, headerRowHeight: params.headerRowHeight || params.rowHeight, sheetName: sheetName,
excelFactory: excelFactory, baseExcelStyles: this.gridOptions.excelStyles || [], styleLinker: this.styleLinker.bind(this) });
return new (isXlsx ? ExcelXlsxSerializingSession : ExcelXmlSerializingSession)((config));
};
ExcelCreator.prototype.styleLinker = function (rowType, rowIndex, colIndex, value, column, node) {
if ((rowType === RowType.HEADER) || (rowType === RowType.HEADER_GROUPING)) {
return ["header"];
}
var styles = this.gridOptions.excelStyles;
if (!styles || !styles.length) {
return null;
}
var styleIds = styles.map(function (it) {
return it.id;
});
var applicableStyles = [];
this.stylingService.processAllCellClasses(column.getColDef(), {
value: value,
data: node.data,
node: node,
colDef: column.getColDef(),
rowIndex: rowIndex,
api: this.gridOptionsWrapper.getApi(),
columnApi: this.gridOptionsWrapper.getColumnApi(),
$scope: null,
context: this.gridOptionsWrapper.getContext()
}, function (className) {
if (styleIds.indexOf(className) > -1) {
applicableStyles.push(className);
}
});
return applicableStyles.sort(function (left, right) {
return (styleIds.indexOf(left) < styleIds.indexOf(right)) ? -1 : 1;
});
};
ExcelCreator.prototype.isExportSuppressed = function () {
return this.gridOptionsWrapper.isSuppressExcelExport();
};
ExcelCreator.prototype.setExportMode = function (exportMode) {
this.exportMode = exportMode;
};
ExcelCreator.prototype.getExportMode = function () {
return this.exportMode || 'xlsx';
};
ExcelCreator.prototype.packageFile = function (data) {
if (this.getExportMode() === 'xml') {
return _super.prototype.packageFile.call(this, data);
}
var _a = this, zipContainer = _a.zipContainer, xlsxFactory = _a.xlsxFactory;
zipContainer.addFolders([
'xl/worksheets/',
'xl/',
'xl/theme/',
'xl/_rels/',
'docProps/',
'_rels/'
]);
zipContainer.addFile('xl/worksheets/sheet1.xml', data);
zipContainer.addFile('xl/workbook.xml', xlsxFactory.createWorkbook());
zipContainer.addFile('xl/styles.xml', xlsxFactory.createStylesheet());
zipContainer.addFile('xl/sharedStrings.xml', xlsxFactory.createSharedStrings());
zipContainer.addFile('xl/theme/theme1.xml', xlsxFactory.createTheme());
zipContainer.addFile('xl/_rels/workbook.xml.rels', xlsxFactory.createWorkbookRels());
zipContainer.addFile('docProps/core.xml', xlsxFactory.createCore());
zipContainer.addFile('[Content_Types].xml', xlsxFactory.createContentTypes());
zipContainer.addFile('_rels/.rels', xlsxFactory.createRels());
return zipContainer.getContent('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
};
__decorate([
Autowired('excelXmlFactory')
], ExcelCreator.prototype, "excelXmlFactory", void 0);
__decorate([
Autowired('excelXlsxFactory')
], ExcelCreator.prototype, "xlsxFactory", void 0);
__decorate([
Autowired('columnController')
], ExcelCreator.prototype, "columnController", void 0);
__decorate([
Autowired('valueService')
], ExcelCreator.prototype, "valueService", void 0);
__decorate([
Autowired('gridOptions')
], ExcelCreator.prototype, "gridOptions", void 0);
__decorate([
Autowired('stylingService')
], ExcelCreator.prototype, "stylingService", void 0);
__decorate([
Autowired('downloader')
], ExcelCreator.prototype, "downloader", void 0);
__decorate([
Autowired('gridSerializer')
], ExcelCreator.prototype, "gridSerializer", void 0);
__decorate([
Autowired('gridOptionsWrapper')
], ExcelCreator.prototype, "gridOptionsWrapper", void 0);
__decorate([
Autowired('zipContainer')
], ExcelCreator.prototype, "zipContainer", void 0);
__decorate([
PostConstruct
], ExcelCreator.prototype, "postConstruct", null);
ExcelCreator = __decorate([
Bean('excelCreator')
], ExcelCreator);
return ExcelCreator;
}(BaseCreator));
export { ExcelCreator };
|