Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date format in sheet_to_json #705

Closed
zhangge3992513 opened this issue Jun 23, 2017 · 7 comments
Closed

date format in sheet_to_json #705

zhangge3992513 opened this issue Jun 23, 2017 · 7 comments

Comments

@zhangge3992513
Copy link

How do I get the content in the excel table without converting the format?
I don't want to convert it.
in my excel,has a auto format cell : 2017/6/13 14:13:12
xlsx get that: 6/13/17 14:13
I need the data: 2017/6/13 14:13:12
and I need to save the data to postgresql

@zhangge3992513
Copy link
Author

set
cellText:false,
dateNF:'yyyy/mm/dd h:mm:ss'

maybe I solve my question,
but,the dateNF convert '16:12:55' to '1900/01/00 16:12:55'
I just need '16:12:55'.

I wanna cry!😭

@SheetJSDev
Copy link
Contributor

@zhangge3992513 set cellDates:true in the read function, then every cell encoding a date will have a JS Date value.

If you know that certain dates are really times, then change those cells! Here's how you change the format of cell B2 in sheet Sheet1:

var worksheet = workbook.Sheets['Sheet1'];
var cell = worksheet['B2'];
delete cell.w; // remove old formatted text
cell.z = 'h:mm:ss'; // set cell format
/* OPTIONAL */
XLSX.utils.format_cell(cell); // this refreshes the formatted text.

@zhangge3992513
Copy link
Author

Well, thank you. That solves my problem.But I don't think it's a very good way.
I have a suggestion:
Add a time type and add timeNF in Parsing Options,
maybe it will be very convenient to format time .

@SheetJSDev
Copy link
Contributor

The real problem is the default date format is localized. See #326 (comment) for a larger discussion. If you set your computer settings to US English, you will see 6/13/17 14:13, but in other locales you will see different date formats.

This is a known issue with our formatter library https://github.com/SheetJS/ssf, so we'll mark this issue as closed and update once we figure out international support

@jcalfee
Copy link

jcalfee commented Sep 19, 2020

Is there a way to get the formatted date and time strings (unaltered just as recorded in the spreadsheet) in the JSON output?

The cellDates formatter option converts it to UTC and changes the date or time. It appears that cellText: true is what I need, but when I have that enabled I just get numbers in the JSON Date and Time fields.

image

My code is coded to sheet_to_json but due to the logic I need, I'm finding it very hard to lookup the cell from any point in the JSON. If I could, I'm after the w value from any place in the JSON.

> wb.Sheets.WebhookTest.R2
{ t: 'n', v: 44084, w: '10/09/2020' }

> wb.Sheets.WebhookTest.S2
{ t: 'n', v: 44091.3958333333, w: '9:30 AM' }

@SandipUmapEcotech
Copy link

set cellText:false, dateNF:'yyyy/mm/dd h:mm:ss'

maybe I solve my question, but,the dateNF convert '16:12:55' to '1900/01/00 16:12:55' I just need '16:12:55'.

I wanna cry!😭

const rows = XLSX.utils.sheet_to_json(workbook.Sheets[sheet], {raw: false}
use {raw:false} it will read accurate as written in excel

@SandipUmapEcotech
Copy link

set {cellDates: true ,dateNF: "DD-MMM-YYYY"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants