简体   繁体   中英

How to create an excel file in react js with custom headings and styles while doing export to excel?

I need to generate an excel in the below format where some headers column are single row and some are multi row and multi column. Also need to add CSS to headings like background color and borders.

i couldn't find any proper solution. All solutions I got were for converting array to excel file.

click here to view the format needed.

use SheetJS library

const headerTitle = 'your header title here';
const sheet = XLSX.utils.json_to_sheet([{}], {
  header: [headerTitle],
});
XLSX.utils.sheet_add_json(sheet, data, { origin: 'A3' });
XLSX.utils.book_append_sheet(workbook, sheet);
XLSX.writeFile(workbook, 'fileName.xls');

where headerTitle name is the header column, data is the excel file data in array forma

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM