Recent

Author Topic: FPSPreadsheet doesn't read/write files  (Read 8605 times)

yellowbit

  • New Member
  • *
  • Posts: 22
FPSPreadsheet doesn't read/write files
« on: November 29, 2012, 09:44:09 pm »
I've tried to use an example from this link: http://wiki.freepascal.org/FPSpreadsheet#Excel_5_example

It's very simple code, but I get this message:
Quote
Tried to write a spreadsheet using an unsupported format.

Every format causes this error.

I think the file path is OK. What can be wrong? Does it require the MS Office installed (I have only Libre Office) ?
« Last Edit: November 29, 2012, 09:49:10 pm by yellowbit »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: FPSPreadsheet doesn't read/write files
« Reply #1 on: November 30, 2012, 08:21:59 am »
What can be wrong? Does it require the MS Office installed (I have only Libre Office) ?
1. You don't show any code so I don't know what can be wrong. No permissions to the directory/file? Wrong filename? Please include code. See my signature for more tips on how to ask questions.
2. No you don't need MS Office, Libre Office or anything else (except the requirements mentioned on the fpspreadsheet wiki page.

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

yellowbit

  • New Member
  • *
  • Posts: 22
Re: FPSPreadsheet doesn't read/write files
« Reply #2 on: November 30, 2012, 04:22:45 pm »
You don't show any code so I don't know what can be wrong.
My code is almost the same as shown under the link in the first post (added OpenFileDialog to get the file name). I'm sure the file path is valid and I'm running as the administrator.

Code: [Select]
{
excel5demo.dpr
 
Demonstrates how to write an Excel 5.x file using the fpspreadsheet library
 
You can change the output format by changing the OUTPUT_FORMAT constant
 
AUTHORS: Felipe Monteiro de Carvalho
}
program excel5demo;
 
{$mode delphi}{$H+}
 
uses
  Classes, SysUtils, fpspreadsheet, fpsallformats, fpspreadsheet_pkg;
 
const OUTPUT_FORMAT = sfExcel5;
 
var
  MyWorkbook: TsWorkbook;
  MyWorksheet: TsWorksheet;
  MyFormula: TsRPNFormula;
  MyDir: string;
begin
  // Initialization
  MyDir := ExtractFilePath(ParamStr(0));
 
  // Create the spreadsheet
  MyWorkbook := TsWorkbook.Create;
  MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet');
 
  // Write some number cells
  MyWorksheet.WriteNumber(0, 0, 1.0);
  MyWorksheet.WriteNumber(0, 1, 2.0);
  MyWorksheet.WriteNumber(0, 2, 3.0);
  MyWorksheet.WriteNumber(0, 3, 4.0);
 
  // Write the formula E1 = A1 + B1
  // or, in RPN: A1, B1, +
  SetLength(MyFormula, 3);
  MyFormula[0].ElementKind:=fekCell; {A1}
  MyFormula[0].Col := 0;
  MyFormula[0].Row := 0;
  MyFormula[1].ElementKind:=fekCell; {B1}
  MyFormula[1].Col := 1;
  MyFormula[1].Row := 0;
  MyFormula[2].ElementKind:=fekAdd;;  {+}
  MyWorksheet.WriteRPNFormula(0, 4, MyFormula);
 
  // Creates a new worksheet
  MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2');
 
  // Write some string cells
  MyWorksheet.WriteUTF8Text(0, 0, 'First');
  MyWorksheet.WriteUTF8Text(0, 1, 'Second');
  MyWorksheet.WriteUTF8Text(0, 2, 'Third');
  MyWorksheet.WriteUTF8Text(0, 3, 'Fourth');
 
  // Save the spreadsheet to a file
  MyWorkbook.WriteToFile(MyDir + 'test' + STR_EXCEL_EXTENSION, OUTPUT_FORMAT);
  MyWorkbook.Free;
end.
« Last Edit: November 30, 2012, 04:27:55 pm by yellowbit »

paweld

  • Hero Member
  • *****
  • Posts: 1561
Re: FPSPreadsheet doesn't read/write files
« Reply #3 on: November 30, 2012, 07:33:04 pm »
lazarus 1.0.2, fpc 2.6.0, win 7 x64, fpspreadsheet from svn
Best regards / Pozdrawiam
paweld

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: FPSPreadsheet doesn't read/write files
« Reply #4 on: December 01, 2012, 11:39:55 am »
Thanks paweld ;) Was just about to upload my own version when I saw you had uploaded the attachment.
The example code posted by yellowbit works fine for me with fpspreadsheet svn (and FPC 2.6.1) as long as I comment out the fpspreadsheet_pkg unit as that doesn't seem to exist (or I'm to stupid to find it - in any case, it works without the unit)
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

yellowbit

  • New Member
  • *
  • Posts: 22
Re: FPSPreadsheet doesn't read/write files
« Reply #5 on: December 01, 2012, 09:03:12 pm »
Thanks, paweld! I've found the problem. It was missing "fpsallformats" in the "uses" section. The program was compiled without errors, so I haven't noticed this missing word.

Pozdrowienia z Krakowa  8)

 

TinyPortal © 2005-2018