I'm exporting a json to an Excel workbook using the React XLSX library and I need to format the cells, for example, color the headers and autofit to the content.
I leave my code that exports the json to the Excel workbook:
const exportExcel = () => {
let valuesToExport = objectsFromCols();
const worksheet = xlsx.utils.json_to_sheet(valuesToExport);
const workbook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };
const excelBuffer: any = xlsx.write(workbook, { bookType: 'xlsx', type: 'array' });
saveAsExcelFile(excelBuffer, dt.props.exportFilename);
}
const saveAsExcelFile = (buffer: any, fileName: string): void => {
let EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
let EXCEL_EXTENSION = '.xlsx';
const data: Blob = new Blob([buffer], {
type: EXCEL_TYPE
});
saveAs(data, fileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION);
}
Thank you very much for the answers in advance.
The XLSX library does not support styles in the community version, only in its paid PRO version.