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

Schema not being applied #68

Closed Schwoebel closed 4 years ago

Schwoebel commented 4 years ago

I'm using Node 11 and read-excel-file 4.0.5

When I supply a Schema:

const schema = {
  "CC-CODE": {
    prop: "code",
    required: true,
    type: String
  },
  "DEFINITION": {
    prop: "definition",
    required: true,
    type: String
  },
  "ENGLISH": {
    prop: "english",
    required: true,
    type: String
  },
  "SWEDISH": {
    prop: "swedish",
    required: true,
    type: String
  },
  "BLISS": {
    prop: "bliss",
    required: true,
    type: String
  },
  "ARASAAC": {
    prop: "arasaac",
    required: true,
    type: String
  }, 
  "CATEGORIES": {
    prop: "categories",
    required: true,
    type: String
  }
};

and apply it to: var sheet = readXlsxFile('data.xlsx',{schema});

I'm not getting back {rows, errors} I'm getting data just as if I had never used a schema.

catamphetamine commented 4 years ago

Perhaps your excel file column headers don't match. Or perhaps the header row is not the first row.

Schwoebel commented 4 years ago

I wish that were the case.

But I dumbed it down as much as possible by making a test excel with TEST in A1, the string 'test' in A2, and the string "test again" in A3.

const schema = {
  TEST: {
    prop: "test",
    required: true,
    type: String,
  },
};

is my schema and it still produces this: [ [ 'TEST' ], [ 'test' ], [ 'test' ] ]

could this be an excel thing?

any other way I could test this?

catamphetamine commented 4 years ago

Looks like you're arranging columns in rows. So the behavior is as expected. This library doesn't support columns-as-rows layout.

Schwoebel commented 4 years ago

That's not what I'm doing. To show you that there is something wrong, I copied the example from your readme.

Screenshot 2020-02-03 at 09 54 58 and used your schema (leaving out the parsing of the phone number and just using it as a string)

by your readme's descrption I should get

{rows: [{ date: '03/24/2018', numberOfStudents: 123, course: {isFree: true, title: Chemistry}, contact: '(123) 456-7890'}], errors: []}

but I don't.

I get this:

[ [ 'Start Date',
    'Number of Students',
    'Is Free',
    'Course Title',
    'Contact' ],
  [ '03/24/2018', 123, true, 'Chemistry', '(123) 456-7890' ] ]
catamphetamine commented 4 years ago

Maybe. Still, you're the only one having the issue. Until there're other people with similar issues, I guess this shouldn't be open. As for the reason of the behavior you're observing: only you could find out what's going on there. You could insert console.log()s somewhere in node_modules/read-excel-file/commonjs or modules and see what's going on. But that would be a long process. Perhaps you'd better use some other library.

Schwoebel commented 4 years ago

You're right.

The screwy thing about this is that it worked for 6 months and then started doing this out of the blue. No updates done, nothing.

I think your library was great when it was working, but something is going wrong somewhere. Most undoubtedly on my end.

If anyone runs into this with Microsoft Excel for Mac Version 16.27 I wish them luck.

mohniaz-com commented 4 years ago

+1 Having the same issue

Thivarella commented 3 years ago

Having the same issue. Has someone found a way to correct this?