catamphetamine / read-excel-file

Read *.xlsx files in a browser or Node.js. Parse to JSON with a strict schema.
https://catamphetamine.gitlab.io/read-excel-file/
MIT License
301 stars 52 forks source link

Merged cells Xlsx to json parsing #105

Open TSergey123 opened 2 years ago

TSergey123 commented 2 years ago

Hey everyone, Thanks a lot for your library, appreciate the work that you have done, but I have an unusual problem. what can I do with merged cells in one line? my code:

const readXlsxFile = require("read-excel-file/node");

const schema = {
 "ClientCateg": {
  prop: "ClientCateg",
  type: String,
 },
 "Place": {
  prop: "Place",
  type: String,
 },
 "Price": {
  prop: "price",
  type: {
   "SummFrom": {
    prop: "SummFrom",
    type: String,
   },
   "SummTo": {
    prop: "SummTo",
    type: String,
   },
  },
 },
};
readXlsxFile("template-blanks1.xlsx", { schema }).then(({ rows, errors }) => {
 errors.length === 0;
  console.log(rows);
});

my result: [ { ClientCateg: firstCateg', Place: 'Inside', price: { summFrom: '100000', summTo: '2999999.99' } }, { price: { summFrom: '3000000', summTo: '7000000' } }, { ClientCateg: 'SecondCateg', Place: 'Outside', price: { summFrom: '100000', summTo: '2999999.99' } }, { price: { summFrom: '3000000', summTo: '7000000' } } ] screen

As you can see, for merged cells in one line, it creates a new object, but I need all data from a row, to be in one object

catamphetamine commented 2 years ago

Hi. It's strange that it doesn't return all data. I'd assume it would return every row (with duplicates).

You could provide the file and I could maybe hypothetically look at it in some future, or maybe not.

You could debug it yourself: the library's code is pretty simple.

TSergey123 commented 2 years ago

Incredible, you answered instantly) I have already tried more than a dozen libraries and everyone has this problem. Even if I manage to return all the rows, they will return null


{ ClientCat: 'FirstCat',
 Place: 'Inside',
List: '*',
Acceptable: 'true',
Program: Special,
Code: 'I1',
Name: Product 'sort'
},
{
ClientCat: null, productCode: null,
CreditType: null,
SummFrom: null,
SummTo: null,
TermFrom: 1,
undefined: 360,
PvMin: 15,
PvMid: 19.99,
PVMax: 20,
Procent: null },
catamphetamine commented 2 years ago

I have already tried more than a dozen libraries and everyone has this problem. Even if I manage to return all the rows, they will return null

That's how Excel file format works: the value is only written in the top row in a group, and then all other rows have nulls. The cell being vertically expanded is just a visual effect.

TSergey123 commented 2 years ago

Yes it is. But maybe there is some way to adapt to this visual effect?

catamphetamine commented 2 years ago

I think there could be: a library could duplicate the top row value onto the other rows when it sees that a cell has a "col span" attribute.