excel icon indicating copy to clipboard operation
excel copied to clipboard

Date Fields in file

Open fabioselau077 opened this issue 4 years ago • 13 comments

Hello, how do I receive the fields as Date? I have a column with the fields as Date but when I order to display some numbers appear. For example the date in the file is: 08/05/2020 12:00:00 No Flutter in print (as your example) appears: 43959.5 How to solve?

fabioselau077 avatar May 27 '20 03:05 fabioselau077

Started working on this in beta (unstable) branch :: https://github.com/kawal7415/excel/tree/beta

As we had started to work on providing Formula functionality, So we will be providing various CellType support.

Thank You Stay Tuned... Long Live Open S🔥urce

justkawal avatar May 27 '20 11:05 justkawal

Is there a solution for this problem. I still am not able to recieve fields as date.

Excel only recieves the fields as date if it is in the first column. For columns other than that, I get values such as 43959.

st99 avatar Aug 29 '20 07:08 st99

Hello, how do I receive the fields as Date? I have a column with the fields as Date but when I order to display some numbers appear. For example the date in the file is: 08/05/2020 12:00:00 No Flutter in print (as your example) appears: 43959.5 How to solve?

Hello, did you manage to solve this issue?

yunior123 avatar Oct 21 '20 22:10 yunior123

I am having the same issue indicated above

yunior123 avatar Oct 21 '20 23:10 yunior123

Same issue.

sleepingkit avatar Dec 02 '20 03:12 sleepingkit

Sorry for the issues,

It might take time to push the changes. Contributions are welcome.

Until this covid situation becomes stable, I had to focus on day job to earn a living, other than donations. If you have donated in the past, then I am heartily Thank-full to you. I will be looking into open-source packages at weekends.

justkawal avatar Dec 02 '20 04:12 justkawal

I found out about a workaround until this is officially fixed. Please take a look at this article that explains that number means. You can write a simple function to convert this number into a DateTime.

How Dates Work in Excel – The Calendar System Explained + Video

Each Day is a Whole Number Each day is represented by one whole number in Excel. Type a 1 in any cell and then format it as a date. You will get 1/1/1900. The first day of the calendar system.

Type a 2 in a cell and format it as a date. You will get 1/2/1900, or January 2nd. This means that one whole day is represented by one whole number is Excel. You can also take a cell that contains a date and format it as a number.

For example, this post was published on 1/27/2016. Put that number in a cell (the keyboard shortcut to enter today's date is Ctrl+;), and then format it as a number or General. You will see the number 42,396. This is the number of days that have elapsed since 1/1/1900.

nipunasudha avatar Dec 07 '20 05:12 nipunasudha

Also, the date value that we receive is not consistent. The CellTypes are either string or integer and it is pretty random as you can see here. It makes it very difficult to identify if a cell is an integer or date in disguise. For a sheet with a predetermined date column, it would be easy to convert them to DateTime depending on its type (string or int) but not for a generalized sheet. It would be great if you could also introduce a new CellType.date and return an actual DateTime object instead of a string/int.

ashishbeck avatar May 07 '21 07:05 ashishbeck

Or you could simply return the default string value as it appears on the Excel (dd-mm-yyyy) and let us parse it. That would be really simple and easy.

ashishbeck avatar May 07 '21 07:05 ashishbeck

@ashishbeck Structure of excel doesn't support to have normal date as String, If I would have done that way then the excel file would have easily broken on Google Sheets,, Sheets from the Apple software and also on Microsoft Excel.

I thinks that the answer from @nipunasudha would be promising to help you out in this scenario until I push a fix for it.

justkawal avatar May 07 '21 07:05 justkawal

Of course, it must be a stress for you to dedicate to things outside of work and we are really grateful for it. All I can hope for is you to push fixes whenever possible.

ashishbeck avatar May 07 '21 18:05 ashishbeck

Awaiting for DateTime column )

Bes79 avatar Jul 27 '21 13:07 Bes79

Here's a simple static util method I use to convert excel dates to DateTime. Hope this helps :)

  import 'package:jiffy/jiffy.dart';

  static DateTime tryParseExcelDateTimeDouble(double dateDouble, {DateTime ifInvalid}) {
    if (dateDouble == null || dateDouble < 1) return ifInvalid;
    return Jiffy(DateTime(1900, 1, 1))
        .add(days: dateDouble.toInt() - 1)
        .dateTime;
  }

nipunasudha avatar Aug 27 '21 13:08 nipunasudha

@nipunasudha your solution worked for me THANKS with just small issue its showing me one day ahead. Is that a big problem or should i manually add 1 day to it.

MalikSamiAwan avatar Nov 24 '22 13:11 MalikSamiAwan

Here's a simple static util method I use to convert excel dates to DateTime. Hope this helps :)

  import 'package:jiffy/jiffy.dart';

  static DateTime tryParseExcelDateTimeDouble(double dateDouble, {DateTime ifInvalid}) {
    if (dateDouble == null || dateDouble < 1) return ifInvalid;
    return Jiffy(DateTime(1900, 1, 1))
        .add(days: dateDouble.toInt() - 1)
        .dateTime;
  }

It'll work if you change dateDouble.toInt() - 1 to dateDouble.toInt() - 2

BugsBuggy avatar Nov 24 '22 19:11 BugsBuggy

Is there a way to set a cell as a Date when exporting Excel?

joe-mybuzz avatar Dec 12 '22 14:12 joe-mybuzz

@BugsBuggy and how can we store date values?

MalikSamiAwan avatar Feb 16 '23 21:02 MalikSamiAwan

Any news?

Bes79 avatar Jul 04 '23 22:07 Bes79

I implemented the support for date, time and date-time values, here is the PR: https://github.com/justkawal/excel/pull/279 And so you may also use it like this as long as it is not available in the main branch:

# pubspec.yaml

dependencies:
  excel
    git: https://github.com/quaaantumdev/excel.git

( the repository may be deleted once the changes are merged )

quaaantumdev avatar Nov 06 '23 00:11 quaaantumdev

Can you try version:

excel: ^4.0.0

justkawal avatar Nov 25 '23 23:11 justkawal