简体   繁体   English

读取 xls 文件正在使用库 xlsx 返回 html 标记

[英]Reading xls file is returning html tags using library xlsx

I am using xlsx library of nodejs for reading xls file.我正在使用 nodejs 的 xlsx 库来读取 xls 文件。 According to the document the library supports xls file format.根据文档,该库支持 xls 文件格式。 On reading I am getting html tags along with it.在阅读时,我收到了 html 标签。 I can remove the html tags using regex or replace function but does the library give support to do that as I couldn't find it in the documentation?我可以使用正则表达式删除 html 标签或替换 function 但该库是否支持这样做,因为我在文档中找不到它?

Excel File format: Microsoft Excel 97-2003 Worksheet (.xls) Excel 文件格式:Microsoft Excel 97-2003 工作表 (.xls)

The demo link they have provided in their documentation https://oss.sheetjs.com/sheetjs/ works but when I try to do the same with my code it doesn't give the desired result.他们在文档https://oss.sheetjs.com/sheetjs/中提供的演示链接有效,但是当我尝试对我的代码执行相同操作时,它没有给出预期的结果。

let xlsx = require('xlsx');
let fs = require('fs');

let workBookData = xlsx.readFile('data.xls'); // parses a file
console.log(workBookData);

Here is an image of the result I am getting.这是我得到的结果的图像。

在此处输入图像描述

"workBookData" represent in memory excel sheets. “workBookData”在 memory excel 表中表示。 In order to convert it to json object you will have to use utilitiy methods provided by sheetjs为了将其转换为 json object 您将不得不使用 sheetjs 提供的实用方法

For example:例如:

  const workBookData = xlsx.readFile(file.path);
  const sheetNames = Object.keys(workbook.Sheets);

  sheetNames.forEach((sheetName)=>{
    let sheetObj= xlsx.utils.sheet_to_json(workBookData.Sheets[sheetName]);
    console.log(sheetObj);
  });

This was an issue/bug in the library.这是库中的一个问题/错误。 A PR has been created for this and it will be fixed in the new version of the library.为此创建了一个 PR,它将在新版本的库中得到修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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