Add various extensions to the xlsx exporter

This commit is contained in:
Sean Engelhardt 2019-04-29 14:54:46 +02:00
parent 3dd659ae36
commit d05a30bccb

View File

@ -16,6 +16,16 @@ import { XlsxExportServiceService, CellFillingDefinition } from 'app/core/ui-ser
providedIn: 'root'
})
export class MotionXlsxExportService {
/**
* Determine the default font size
*/
private fontSize = 12;
/**
* The defa
*/
private fontName = 'Arial';
/**
* 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
*
@ -57,11 +81,19 @@ export class MotionXlsxExportService {
const worksheet = workbook.addWorksheet(this.translate.instant('Motions'), {
pageSetup: {
paperSize: 9,
orientation: 'portrait',
orientation: 'landscape',
fitToPage: true,
fitToHeight: 5,
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 => {
cell.font = {
name: this.fontName,
size: this.fontSize,
underline: true,
bold: true
};
@ -97,14 +131,25 @@ export class MotionXlsxExportService {
return this.translate.instant(motionProp.toString());
}
} else {
return null;
return '';
}
})
);
// add to sheet
for (const motion of motionData) {
worksheet.addRow(motion);
for (let i = 0; i < motionData.length; i++) {
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);