Recent

Author Topic: [solved] tsWokSheetGrid invalid character error  (Read 3705 times)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
[solved] tsWokSheetGrid invalid character error
« on: May 11, 2017, 07:25:26 pm »
I have an ODS file that has a separate column for translations in 20 different languages. With Chinese and many other languages there is a need for special characters. The spreadsheet looks perfect in Open Office.

I've placed a tsWorkSheetGrid on my form but I get an error when Grid.LoadFromFile('MyFile.ods') is executed.

       ...raised exception class 'EXMLReadError' with message: In "file:MyFile.ods' (line 1 pos 3): Invalid character

        In file 'laz2_xmlread.pas' at line 1517:
        raise E;

Is there a setting in tsWorkSheetGrid that will allow it to accommodate all these translations?
« Last Edit: May 12, 2017, 12:52:22 am by bobonwhidbey »
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: tsWokSheetGrid invalid character error
« Reply #1 on: May 11, 2017, 10:59:42 pm »
fpspreadsheet uses utf8, so your translation table should not pose any problem.

Without knowing any more details I cannot comment on the reason why this file is crashing fpspreadsheet. Can you post the file here? (rename its extension to zip to make it acceptable for the forum software). Of, if you don't want to publish the file send me a PM.

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: tsWokSheetGrid invalid character error
« Reply #2 on: May 11, 2017, 11:15:25 pm »
I cut it down to just a few lines, but had the exact same problem. Here's the small file.
« Last Edit: May 11, 2017, 11:31:38 pm by bobonwhidbey »
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: tsWokSheetGrid invalid character error
« Reply #3 on: May 11, 2017, 11:43:42 pm »
Hmmmh...

I can load the file without any issues. Load the project fpsgrid in the examples/visual folder, and retry.

What is your fpspreadsheet version, your Lazarus version, your OS?
Can you show the code that you use to load the file? Does the uses list contain the unit fpsopendocument (or fpsallformats)? Ideally you should try to condense the relevant parts of your program into a little demo which you upload here (only pas, lfm, lpi and lpr files packed into a shared zip).

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: tsWokSheetGrid invalid character error
« Reply #4 on: May 12, 2017, 12:11:48 am »
Here's a very simple program [attached]....just a grid and a single command:
  Grid.LoadFromFile('MyGrid.ods');   

I'm using Win10 64-bit, FPC 3.0, Laz 1.7

My TsWorksheetGrid component is on the FPSpreadsheet tab. I installed
 it from fpspreadsheet-v1.8

I've used it in other programs with good success.

With this zip file as well as the previous zip file, you will need to extract to get the files
« Last Edit: May 12, 2017, 12:21:25 am by bobonwhidbey »
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: tsWokSheetGrid invalid character error
« Reply #5 on: May 12, 2017, 12:30:55 am »
TsWorksheetGrid inherits from one of its ancestors the public method LoadfromFile, but this is not the method that we need. Call LoadFromSpreadsheetFile instead. Note that there are several overloads to select a particular reader and/or to load a partcular sheet:

Code: Pascal  [Select][+][-]
  1.     procedure LoadFromSpreadsheetFile(AFileName: string;
  2.       AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer = -1); overload;
  3.     procedure LoadFromSpreadsheetFile(AFileName: string;
  4.       AFormatID: TsSpreadFormatID = sfidUnknown; AWorksheetIndex: Integer = -1); overload;
  5.     procedure LoadSheetFromSpreadsheetFile(AFileName: String;
  6.       AWorksheetIndex: Integer = -1; AFormatID: TsSpreadFormatID = sfidUnknown);
  7.  

 And in order to select the correct file reader the unit fpsopendocument (or fpsallformats) must be in the uses list of the unit:

Code: Pascal  [Select][+][-]
  1. uses
  2.   ..., fpsopendocument, ...
  3.  
  4. procedure TForm1.FormShow(Sender: TObject);
  5. begin
  6.   Grid.LoadFromSpreadsheetFile('MyGrid.ods');  // automatic format selection from file name extension
  7. end;

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: tsWokSheetGrid invalid character error
« Reply #6 on: May 12, 2017, 12:52:03 am »
Thank you very much WP.  That's all it took.
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018