Recent

Author Topic: Fpspreadsheet patch set: date,time functions, overflow protection  (Read 7489 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Pls find attached my current patchset against fpspreadsheet.
- Added DATE, TIME worksheet functions in Excel. Date output works ok; however you'll still need to manually switch formatting to date/time
- use fpc- provided tzipper function if on FPC 2.7.1 or higher as it has zip64 support (had already supplied this to bugtracker) edit: can't remember if I had posted this already to the bugtracker, don't think so.
- Respect 32767 character limit in string fields in biff8/xlsx, same with limits in biff2, biff5 and deal with them the same as other overflow is dealt with: throw an exception when writing rather than (as currently) silently corrupting the output. Previously reported as mantis #24988
- cosmetic: added some more references to the openoffice excel documentation chapters

Edit: have only tested with empty times up to now but dates work fine; testing using something like:
Code: [Select]
                  SetLength(ExcelRPNFormula, 9);
                  ExcelRPNFormula[0].ElementKind := fekNum;
// Getting data out of a dataset;
// of course easier to just use a tdatetime or
// even specify a constant number for testing...
                  ExcelRPNFormula[0].DoubleValue := YearOf(TDataset(FDatasets[i]).Fields[TheColumn].AsDateTime);
                  ExcelRPNFormula[1].ElementKind := fekNum;
                  ExcelRPNFormula[1].DoubleValue := MonthOf(TDataset(FDatasets[i]).Fields[TheColumn].AsDateTime);
                  ExcelRPNFormula[2].ElementKind := fekNum;
                  ExcelRPNFormula[2].DoubleValue := DayOf(TDataset(FDatasets[i]).Fields[TheColumn].AsDateTime);
                  ExcelRPNFormula[3].ElementKind := fekDate; //end of date formula
                  ExcelRPNFormula[4].ElementKind := fekNum;
                  ExcelRPNFormula[4].DoubleValue := HourOf(TDataset(FDatasets[i]).Fields[TheColumn].AsDateTime);
                  ExcelRPNFormula[5].ElementKind := fekNum;
                  ExcelRPNFormula[5].DoubleValue := MinuteOf(TDataset(FDatasets[i]).Fields[TheColumn].AsDateTime);
                  ExcelRPNFormula[6].ElementKind := fekNum;
                  ExcelRPNFormula[6].DoubleValue := SecondOf(TDataset(FDatasets[i]).Fields[TheColumn].AsDateTime);
                  ExcelRPNFormula[7].ElementKind := fekTime; //end of time formula
                  ExcelRPNFormula[8].ElementKind := fekAdd; //add date and time
                  ExcelWorksheet.WriteRPNFormula(TheRow, TheColumn, ExcelRPNFormula);
gives formulas like
Quote
=DATE(2011,5,2)+TIME(0,0,0)

Would be happy to split this out in new patches and upload to mantis if somebody wants to commit ;)

As usual, comments welcome as well.

Edit: removed attachment; newer version in other thread
« Last Edit: November 27, 2013, 09:40:07 am by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Fpspreadsheet patch set: date,time functions, overflow protection
« Reply #1 on: November 24, 2013, 11:22:32 am »
Oh, the complete modified fpspreadsheet is used in my bankconvert tool:
https://bitbucket.org/reiniero/smalltools/src
directory bankconvert
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Bart

  • Hero Member
  • *****
  • Posts: 5689
    • Bart en Mariska's Webstek
Re: Fpspreadsheet patch set: date,time functions, overflow protection
« Reply #2 on: November 24, 2013, 12:31:36 pm »
Did you post your fixes in bugtracker (Lazarus CCR section)?
(I'm too lazy to search the bugtracker myself O:-) )

Bart

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Fpspreadsheet patch set: date,time functions, overflow protection
« Reply #3 on: November 24, 2013, 01:38:25 pm »
Hi Bart: as I mentioned in the first post: I posted the overflow fix against the fpspreadsheet package. I actually think I haven't posted the rest yet...

As none of it has been committed, committing the entire thing in one go or split out is fine by me but before I put more work in it I'd like to know if somebody has the time and inclination to do it :)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Bart

  • Hero Member
  • *****
  • Posts: 5689
    • Bart en Mariska's Webstek
Re: Fpspreadsheet patch set: date,time functions, overflow protection
« Reply #4 on: November 24, 2013, 04:01:11 pm »
Felipe Monteiro de Carvalho and Jose Mejuto seem to "own" the fpSpreadSheet section of Lazarus CCR.
You could try asking one of the on Lazarus(Dev) mailinglist.

Bart

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Fpspreadsheet patch set: date,time functions, overflow protection
« Reply #5 on: November 24, 2013, 04:17:52 pm »
Thanks. AFAIU at least one of them is very busy lately ;)

Anyway, I'll keep at it for a while; I think I'm going on a Don Quichotte like quest to try and implement xls date format support ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Fpspreadsheet patch set: date,time functions, overflow protection
« Reply #6 on: November 27, 2013, 09:39:44 am »
Seem to have it working ;)

Topic continued in new thread
http://forum.lazarus.freepascal.org/index.php/topic,22774.0.html
for clarity, with link to download.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018