Difference between revisions of "User talk:Garydale"
Sekelsenmat (talk | contribs) |
(→FPSpreadsheet code to open a file: repsone to Felipe) |
||
Line 55: | Line 55: | ||
: Could you update the wiki for my commit of your patch? thanks --[[User:Sekelsenmat|Felipe Monteiro de Carvalho]] 17:46, 11 August 2011 (CEST) | : Could you update the wiki for my commit of your patch? thanks --[[User:Sekelsenmat|Felipe Monteiro de Carvalho]] 17:46, 11 August 2011 (CEST) | ||
+ | |||
+ | |||
+ | Waiting for you to post a working patch, as per my comments in the bug-tracker. Also, would like to see what you made of my thoughts on the getFileTypeFromName routine. This would have an impact on whatever changes I make to the wiki. | ||
+ | |||
+ | Looking forward to it. |
Revision as of 17:55, 13 August 2011
FPSpreadsheet code to open a file
Hello, there is already a method to read a file in fpspreadsheet regardless of the format: ReadFile
If you don't pass any file format it will attempt to auto-detect the format. At the moment it doesn't differentiate between various XLS formats, just supposes biff8, but it would be better to improve it to do this then to add new code to do the same thing is each app using fpspreadsheet. --Felipe Monteiro de Carvalho 11:13, 2 August 2011 (CEST)
Hello Felipe: Please feel free to use my code to improve the ReadFromFile method. I looked at the code and my routine should be almost a drop-in replacement. Here's my take at it:
<delphi> procedure TsWorkbook.ReadFromFile(AFileName: string); var SheetType: TsSpreadsheetFormat;
valid: Boolean;
procedure getFileType(const FileToUpdate: TFileName; var SheetType: TsSpreadsheetFormat; var valid: Boolean); var suffix: String; begin valid := True; suffix := ExtractFileExt(FileToUpdate); if suffix = STR_EXCEL_EXTENSION then SheetType := sfExcel8 else if suffix = STR_OPENDOCUMENT_CALC_EXTENSION then SheetType := sfOpenDocument else if suffix = STR_OOXML_EXCEL_EXTENSION then SheetType := sfOOXML else if suffix = '.csv' then SheetType := sfCSV else valid := False; end;
begin
getFileType(AFileName, SheetType, valid); if valid then begin try ReadFromFile(AFileName, SheetType); except if SheetType = sfExcel8 then begin repeat try SheetType := Pred(SheetType); ReadFromFile(AFileName, SheetType); valid := True; except
valid := False
end; until valid or (SheetType = sfExcel2); end; end; end;
end; </delphi>
NOTE: I prefer Wirth's later syntax enhancements to his original Algol/Pascal work. In particular, I like his switch to statement lists within closed constructs rather than begin/end blocks. As such, I tend to use begin/end even when they aren't needed, simply to allow statements to be properly closed.
- Could you update the wiki for my commit of your patch? thanks --Felipe Monteiro de Carvalho 17:46, 11 August 2011 (CEST)
Waiting for you to post a working patch, as per my comments in the bug-tracker. Also, would like to see what you made of my thoughts on the getFileTypeFromName routine. This would have an impact on whatever changes I make to the wiki.
Looking forward to it.