Recent

Author Topic: Cell value missing spaces  (Read 1572 times)

sfeinst

  • Full Member
  • ***
  • Posts: 230
Cell value missing spaces
« on: July 18, 2023, 08:31:04 pm »
I'm using v1.14 with ODS files.  I've noticed that when reading a cell value using either ReadAsText from the worksheet or UTF8StringValue for a cell, that spaces after periods are being dropped to 1 space instead of multiple spaces (in my case 2 spaces). 
I'm making a guess that the XML parser being used by the library is causing this to happen, but thought I would check.

Here is some example code:
Code: Pascal  [Select][+][-]
  1. program TestOdsSpace;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   fpspreadsheet, fpstypes, fpsopendocument;
  7.  
  8. var
  9.   Book: TsWorkbook;
  10.   Sheet: TsWorksheet;
  11. begin
  12.   Book := TsWorkbook.Create;
  13.   try
  14.     Book.ReadFromFile('/home/steve/temp/test.ods', sfOpenDocument);
  15.     Sheet := Book.GetFirstWorkSheet;
  16.     writeln(Sheet.ReadAsText(0,0));
  17.     writeln(Sheet.ReadAsText(1,0));
  18.   finally
  19.     Book.Destroy;
  20.   end;
  21. end.
  22.  

I've uploaded the test ODS file.

Not a huge issue, but since I am comparing output with another non-Pascal app which is reading from the same spreadsheet, the diff is throwing differences and is the only reason I even noticed.

wp

  • Hero Member
  • *****
  • Posts: 11995
Re: Cell value missing spaces
« Reply #1 on: July 18, 2023, 10:35:17 pm »
I see - there is a <text:s/> node inside the cell node which has not yet been considered by the ODS reader...

Fixed in the development version on sourceforge-ccr (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/fpspreadsheet/). Note that this fix is not yet contained in the OPM release version.

If you want to patch your version yourself you can do this:
  • Load file fpsopendocument.pas (Make a backup copy first).
  • Find procedure TsSpreadOpenDocReader.ReadLabel
  • To the long case instruction ("case nodename of"), add the "text:s" as a new case
Code: Pascal  [Select][+][-]
  1.         case nodename of  
  2.           [...]
  3.           'text:s':
  4.             AddToCellText(' ');  
  5.           'text:line-break':
  6.             AddToCellText(FPS_LINE_ENDING);
  7.         end;

sfeinst

  • Full Member
  • ***
  • Posts: 230
Re: Cell value missing spaces
« Reply #2 on: July 18, 2023, 10:38:20 pm »
I think you mentioned in another of my posts that the memory leak issue with ods is fixed in svn version and not opm.  Is that true?  If so, I might download the svn version to get both fixes.

wp

  • Hero Member
  • *****
  • Posts: 11995
Re: Cell value missing spaces
« Reply #3 on: July 18, 2023, 10:50:25 pm »
I think you mentioned in another of my posts that the memory leak issue with ods is fixed in svn version and not opm.  Is that true?  If so, I might download the svn version to get both fixes.
Yes. All development and all fixes first go into the svn version. Only after some specific (undefined...) number of changes have accumulated, or after fixes of serious bugs, I prepare a release for OPM.

I think I described in the other thread how you can get the svn version. If you don't use svn I'd recommend to just download the zipped snapshot from that sourceforge page. Unzip it over your current fpspreadsheet installation so that all files are overwritten by the new ones (you may want to make a backup of your old installation to be on the safe side). In most cases the IDE detects automatically that units have changed and recompiles them. If you have compilation errors you should do a clean rebuild of the IDE ("Tools" > "Configure Build Lazarus" > Check "Clean all" and "Switch after building to automatically").

sfeinst

  • Full Member
  • ***
  • Posts: 230
Re: Cell value missing spaces
« Reply #4 on: July 18, 2023, 11:03:54 pm »
Thanks for the steps.  Downloading the zip is probably the way I'll go.

 

TinyPortal © 2005-2018