fpspread - how to open a workbook in read only mode lazarus / 49-FPSpreadsheet ---------------------------------------------------------------------- kjteng · 2017-11-30 08:45 Currently I can open an excel workbook by setting the filename property of the TsWorkbook component. However, this would raise an exception if the workbook is already opened in ms-office (in readwrite mode). Is there a way  to open a workbook in 'read only' TsWorkbook? ---------------------------------------------------------------------- wp · 2017-11-30 09:12 What exactly are you doing? This program opens the file 'test.xls' although it is opened by Excel or LibreOffice: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project2; {$mode objfpc}{$H+} uses  Classes, fpspreadsheet, fpstypes, fpsallformats; var  wb: TsWorkbook;  ws: TsWorksheet;begin  wb := TsWorkbook.Create;  try    wb.ReadFromFile('test.xls', sfExcel8);    ws := wb.GetFirstWorksheet;    WriteLn(ws.ReadAsText(0, 0));  finally    wb.free;  end;   ReadLn;end. ---------------------------------------------------------------------- kjteng · 2017-11-30 12:07 Quote from: wp on November 30, 2017, 10:12:51 amWhat exactly are you doing? Just want to read some info from an excel file only. Your code works. TQ. BTW, how come I got error for ws.ReadAsText(ii, 0) ?   I can only use ws.ReadAsUTF8Text(ii, 0) ? ---------------------------------------------------------------------- wp · 2017-11-30 12:53 Quote from: kjteng on November 30, 2017, 01:07:15 pmhow come I got error for ws.ReadAsText(ii, 0) ?   I can only use ws.ReadAsUTF8Text(ii, 0) ? Then you must have a very old version. 1.8.4 is current release (or use trunk from svn). ---------------------------------------------------------------------- kjteng · 2017-12-01 14:00 Quote from: wp on November 30, 2017, 01:53:38 pmQuote from: kjteng on November 30, 2017, 01:07:15 pmhow come I got error for ws.ReadAsText(ii, 0) ?   I can only use ws.ReadAsUTF8Text(ii, 0) ? Then you must have a very old version. 1.8.4 is current release (or use trunk from svn). TQ.  Downloaded and installed.  Now I have problem in opening .xlsx file. I  get  "[TsSpreadBIFFReader.InternalReadFromStream] Reading o OLE document failed " when I call wb.ReadFromFile('test.xlsx', sfExcel8) method;  The same file can be opened without any problem if I drop a sWorkbookSource1 component onto the form and set sWorkbookSource1.Filename := 'test.xlsx' Any clue? ---------------------------------------------------------------------- wp · 2017-12-01 15:17 In order to read a spreadsheet file you must add the corresponding reader unit to "uses", in case of sfExcel8 (.xls) this is xlsBiff8, in case of the newer .xlsx (sfOOXML) this is xlsOOXML (or: fpsallformats for all built-in speadsheet formats). And you must select the correct format specifier in the wb.ReadFromFile call (or drop it for automatic detection): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  xlsOOXML;[...]  wb.ReadfromFile('test.xlsx', sfOOXML);  // or: wb.ReadFromFile('test.xlsx'); In your call your call  ('ReadFromfile('tst.xlsx', sfExcel8)) you are forcing fpspreadsheet to open the file 'test.xlsx' as an xls file which does not work, of course. ---------------------------------------------------------------------- kjteng · 2017-12-02 00:57 Thanks again for the answer.  Call wb.ReadFromFile(filename)  without the second parameter solve the problem.