Merge pull request #4650 from tsiegleauq/xlsx-addons

Add various extensions to the xlsx exporter
This commit is contained in:
Sean 2019-04-30 10:55:46 +02:00 committed by GitHub
commit 83044acde5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,16 @@ import { XlsxExportServiceService, CellFillingDefinition } from 'app/core/ui-ser
providedIn: 'root' providedIn: 'root'
}) })
export class MotionXlsxExportService { export class MotionXlsxExportService {
/**
* Determine the default font size
*/
private fontSize = 12;
/**
* The defa
*/
private fontName = 'Arial';
/** /**
* Defines the head row style * Defines the head row style
*/ */
@ -30,6 +40,20 @@ export class MotionXlsxExportService {
} }
}; };
/**
* Filling Style of odd rows
*/
private oddFilling: CellFillingDefinition = {
type: 'pattern',
pattern: 'solid',
fgColor: {
argb: 'FFDDDDDD'
},
bgColor: {
argb: 'FFDDDDDD'
}
};
/** /**
* Constructor * Constructor
* *
@ -57,11 +81,19 @@ export class MotionXlsxExportService {
const worksheet = workbook.addWorksheet(this.translate.instant('Motions'), { const worksheet = workbook.addWorksheet(this.translate.instant('Motions'), {
pageSetup: { pageSetup: {
paperSize: 9, paperSize: 9,
orientation: 'portrait', orientation: 'landscape',
fitToPage: true, fitToPage: true,
fitToHeight: 5, fitToHeight: 5,
fitToWidth: properties.length, fitToWidth: properties.length,
printTitlesRow: '1:1' printTitlesRow: '1:1',
margins: {
left: 0.4,
right: 0.4,
top: 1.0,
bottom: 0.5,
header: 0.3,
footer: 0.3
}
} }
}); });
@ -77,6 +109,8 @@ export class MotionXlsxExportService {
worksheet.getRow(1).eachCell(cell => { worksheet.getRow(1).eachCell(cell => {
cell.font = { cell.font = {
name: this.fontName,
size: this.fontSize,
underline: true, underline: true,
bold: true bold: true
}; };
@ -97,14 +131,25 @@ export class MotionXlsxExportService {
return this.translate.instant(motionProp.toString()); return this.translate.instant(motionProp.toString());
} }
} else { } else {
return null; return '';
} }
}) })
); );
// add to sheet // add to sheet
for (const motion of motionData) { for (let i = 0; i < motionData.length; i++) {
worksheet.addRow(motion); const row = worksheet.addRow(motionData[i]);
row.eachCell(cell => {
cell.alignment = { vertical: 'middle', horizontal: 'left', wrapText: true };
cell.font = {
name: this.fontName,
size: this.fontSize
};
// zebra styled filling
if (i % 2 !== 0) {
cell.fill = this.oddFilling;
}
});
} }
this.xlsx.autoSize(worksheet, 0); this.xlsx.autoSize(worksheet, 0);