ReadFromFile failure lazarus / 49-FPSpreadsheet ---------------------------------------------------------------------- TRNelson · 2016-01-14 16:52 Hello, I am pretty new to Lazarus and FPSpreadsheet.  It has been pretty smooth sailing until recently.  An application that I am creating all of a sudden started to fail.  It took me ages to narrow the 'problem' down.  The following code generates an Exception. 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 testread;{$mode objfpc}{$H+}uses  Classes, FileUtil, Dialogs, LazUTF8, fpsTypes, fpspreadsheet, xlsxooxml,  fpsutils;var  workbook                : TsWorkbook;begin  Workbook := TsWorkbook.Create;  Workbook.ReadFromFile('C:\sample.xlsx',sfOOXML);  Workbook.Free;  readln;end.     It compiles with no hints or errors.  When I run it, I get: Project ooxmlread raised exception class 'EXMLReadError' with message: in '' (line 1 pos 290): Invalid #0 character I though perhaps it was because the Excel was invalid.  I created a new XLSX file with Excel and get the same result. The very strange thing is that this all worked until recently.  I uninstalled and reinstalled Lazarus.  It made no different.  As far as I am aware I am using the most recent version of Lazarus and FPSpreadsheet. Any help or thoughts would be greatly appreciated. ---------------------------------------------------------------------- wp · 2016-01-14 16:58 Would you mind to post the xlsx here (pack it into a zip, otherwise the forum software will reject it)? If you don't want to make it public send me a PM how I can grab it somewhere. FPSpreadsheet does not support all features that can be in an xlsx file, and I am not sure if unsupported features cannot crash the program. Ah, and which version of fpspreadsheet are you using? ---------------------------------------------------------------------- eny · 2016-01-14 17:29 Quote from: wp on January 14, 2016, 05:58:35 pmWould you mind to post the xlsx here (pack it into a zip, otherwise the forum software will reject it)? If you don't want to make it public send me a PM how I can grab it somewhere. FPSpreadsheet does not support all features that can be in an xlsx file, and I am not sure if unsupported features cannot crash the program. Ah, and which version of fpspreadsheet are you using? xlsx is already zipped. Simply change the extension. ---------------------------------------------------------------------- TRNelson · 2016-01-14 17:31 I have attached a small ZIP file with the spreadsheet.  It is very simple. I am using fpspreadsheet-1.6.0 ---------------------------------------------------------------------- wp · 2016-01-14 18:07 Sorr, I cannot reproduce your error. I tried Laz-trunk/fpc3/fps-trunk and Laz144/fpc264/fps160 on Win7 Can you recompile the fpspreadsheet package? What is your OS? Which Lazarus version? ---------------------------------------------------------------------- TRNelson · 2016-01-18 05:41 Well, this continues to get very strange.  On a very fresh install of Windows 7 (I was running this on an XP Pro SP3 setup on a different computer initially) , I downloaded and installed Lazarus (version 1.4.4, FPC version 2.6.4, SVN revision 49931).  I loaded the small test program that I showed above.  It worked!  So, now I loaded my original somewhat larger project, compiled it and attempted to run it.  It crashed before completing.  Not unexpected because I am in the early stages of writing it. Disappointingly though, it was the same error noted above. Here's the thing.  Now when I load the previous small example, it crashes every time.  Even after I quite Lazarus and restart. Rebooting the computer does not help. I even uninstalled and re-installed Lazarus and got the same result.  so yes, I have reloaded and compiled the package following the instructions. Something very strange is happening.  Th effect seems to survive a reboot and complete re-installation. I am really at wits end here and any help or suggestion would be greatly appreciated. ---------------------------------------------------------------------- wp · 2016-01-18 09:14 We've heard of strange effects due to dumb anti-virus programs here. For a test, deactivate your anti-virus, or put the folder with your lazarus projects onto a white-list. ---------------------------------------------------------------------- TRNelson · 2016-01-20 05:49 The anti-virus suggestion was intriguing but it didn't make any difference.  I took the entire project to a different computer where I installed Lazarus.  Win 7 system, completely virgin to the Lazarus world.  Loaded and tested the samples that came with the package with no problem.  Loaded my small sample and ran it perfectly.  Loaded and attempted to run my bigger project.  It crashed as expected.  And sadly, as expected, I am back to where I was on my own system. So, well it seemed like a good idea at the time, it has turned into a huge waste of time.  Back to the drawing board and work on a different solution. Thanks for you input though. ---------------------------------------------------------------------- Thaddy · 2016-01-20 06:55 The cause is maybe that on newer versions of windows you are not allowed to write in the system root directory, i.e. c:\ without administrator rights by default. What happens then is that the workbook is probably created with  fmOpenReadWrite as access specifier (or fmCreatre). If this is the case your program will fail because the OS won't allow write mode in C:\ root. Try putting the file in a subdirectory of C:\ and it will probably work ok. Or force the workbook to open in readonly mode if that is sufficient. ---------------------------------------------------------------------- wp · 2016-01-20 08:22 Thaddy, TRNelson's issue occurs during reading. Anyway: trying to write a spreadsheet file in a gui program to the root of C: on my Win7 does not crash the program, the OS only tells me that I don't have sufficient rights and requests me to save it in "My Documents", a console program does not write at all. Anyway, this is a valid point: TRNelson, don't put anything into c:\, the OS will not like that. How did you get that file onto C:\? Maybe it was damaged while doing this? Can you read it with Excel? ---------------------------------------------------------------------- TRNelson · 2016-01-20 18:43 All good suggestions and comments.  The sample in the first post was on an XP machine.  Similar results from the exact same program on Win 7 reading the same Excel file (freshly created with Excel 2010) saved on Drive E: I am starting to narrow the problem down a bit more and wonder if it has something to do with some side affects of WriteToFile (.XLSX).  I seem to be able to use ReadFromFile to read in an .XLS spreadsheet. More pondering and testing later... Thanks for input!