sheetjs 如何获取导入excel的样式呢? #2917

Open
opened 2023-04-12 08:30:18 +00:00 by dxfstart521 · 0 comments

代码如下:
、、、

const reader = new FileReader();
reader.onload = (e) => {
const data = e.target.result;
const workbook = XLSX.read(data, {
cellStyles: true
});

const sheetName = workbook.SheetNames[0];
const sheetTableName = workbook.SheetNames[1];
const sheet = workbook.Sheets[sheetName];

console.log(sheet, 'sheet11111')
let currentSheetjson = XLSX.utils.sheet_to_json(sheet, {
  header: 1, 
  raw: false, 
  blankrows: false,
});

for(let i =0; i<currentSheetjson.length; i ++) {
  const cells: any = currentSheetjson[i]
  console.log(cells, 'cells111')
  for(let j =0; j<cells.length; j++) {
    const cellData = sheet[XLSX.utils.encode_cell({ r: i, c: j })] || {}
    const style = cellData.s ? cellData.s : {}
    console.log(style, 'style111')
  }
}

};
reader.readAsArrayBuffer(file);

、、、

excel如下图:期望可以获取到表格里面单元格以及字体的样式

image

实际代码中没有获取到xslx的样式
image

image

代码如下: 、、、 const reader = new FileReader(); reader.onload = (e) => { const data = e.target.result; const workbook = XLSX.read(data, { cellStyles: true }); const sheetName = workbook.SheetNames[0]; const sheetTableName = workbook.SheetNames[1]; const sheet = workbook.Sheets[sheetName]; console.log(sheet, 'sheet11111') let currentSheetjson = XLSX.utils.sheet_to_json(sheet, { header: 1, raw: false, blankrows: false, }); for(let i =0; i<currentSheetjson.length; i ++) { const cells: any = currentSheetjson[i] console.log(cells, 'cells111') for(let j =0; j<cells.length; j++) { const cellData = sheet[XLSX.utils.encode_cell({ r: i, c: j })] || {} const style = cellData.s ? cellData.s : {} console.log(style, 'style111') } } }; reader.readAsArrayBuffer(file); 、、、 excel如下图:期望可以获取到表格里面单元格以及字体的样式 ![image](/attachments/4a5709eb-b304-4cd5-b448-2c0c24de45b6) 实际代码中没有获取到xslx的样式 ![image](/attachments/64dbf0e6-9428-462e-9f9a-4f51108e2ca1) ![image](/attachments/4d9e5d19-9888-42e9-ad71-8dca7a1289ff)
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#2917
No description provided.