fpspreadsheet: Reintroduce function GetFormatFromFileName. Fixes compilation error of LazReport addition lrSpreadsheetExport.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4395 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-11-22 12:52:00 +00:00
parent 5e055ebbf2
commit b2ca3098a4
2 changed files with 40 additions and 10 deletions

View File

@ -458,7 +458,7 @@ end;
AFormat identifies the file format, see sfXXXX declarations in built-in AFormat identifies the file format, see sfXXXX declarations in built-in
fpstypes. fpstypes.
The system is open for user-defined formats. In this case, AFormat must have The system is open to user-defined formats. In this case, AFormat must have
the value "sfUser". The format identifier is calculated as a negative number, the value "sfUser". The format identifier is calculated as a negative number,
stored in the TsSpreadFormatData class and returned as function result. stored in the TsSpreadFormatData class and returned as function result.
This value is needed when calling fpspreadsheet's ReadFromXXXX and WriteToXXXX This value is needed when calling fpspreadsheet's ReadFromXXXX and WriteToXXXX
@ -484,10 +484,13 @@ begin
raise Exception.Create('[RegisterSpreadFormat] File format name is not specified.'); raise Exception.Create('[RegisterSpreadFormat] File format name is not specified.');
fmt := TsSpreadFormatData.Create(ord(AFormat), AReaderClass, AWriterClass, fmt := TsSpreadFormatData.Create(ord(AFormat), AReaderClass, AWriterClass,
AFormatName, ATechnicalName, AFileExtensions); //, ACanReadFromClipboard, ACanWriteToClipboard); AFormatName, ATechnicalName, AFileExtensions);
n := SpreadFormatRegistry.Add(fmt); n := SpreadFormatRegistry.Add(fmt);
if AFormat = sfUser then if (AFormat = sfUser) then
begin
if (n <= ord(sfUser)) then n := n + ord(sfUser) + 1;
fmt.FFormatID := -n; fmt.FFormatID := -n;
end;
Result := fmt.FormatID; Result := fmt.FormatID;
end; end;

View File

@ -105,8 +105,10 @@ function TryStrToErrorValue(AErrorStr: String; out AErr: TsErrorValue): boolean;
//function GetFileFormatName(AFormat: TsSpreadsheetFormat): string; //function GetFileFormatName(AFormat: TsSpreadsheetFormat): string;
//function GetFileFormatExt(AFormat: TsSpreadsheetFormat): String; //function GetFileFormatExt(AFormat: TsSpreadsheetFormat): String;
//function GetFormatFromFileName(const AFileName: TFileName; function GetFormatFromFileName(const AFileName: TFileName;
// out SheetType: TsSpreadsheetFormat): Boolean; out AFormatID: TsSpreadFormatID): Boolean; overload;
function GetFormatFromFileName(const AFileName: TFileName;
out SheetType: TsSpreadsheetFormat): Boolean; overload; deprecated 'Use overloaded function with TsSpreadsheetID';
function IfThen(ACondition: Boolean; AValue1,AValue2: TsNumberFormat): TsNumberFormat; overload; function IfThen(ACondition: Boolean; AValue1,AValue2: TsNumberFormat): TsNumberFormat; overload;
@ -191,7 +193,7 @@ var
implementation implementation
uses uses
Math, lazutf8, lazfileutils, fpsStrings; Math, lazutf8, lazfileutils, fpsStrings, fpsRegFileFormats;
{******************************************************************************} {******************************************************************************}
{ Endianess helper functions } { Endianess helper functions }
@ -1087,19 +1089,43 @@ begin
else raise Exception.Create(rsUnknownSpreadsheetFormat); else raise Exception.Create(rsUnknownSpreadsheetFormat);
end; end;
end; end;
*)
{@@ ----------------------------------------------------------------------------
Determines the spreadsheet type from the file type extension
@param AFileName Name of the file to be considered
@param AFormatID File format ID found from analysis of the extension (output)
@return True if the file matches any of the registered formats, false otherwise
-------------------------------------------------------------------------------}
function GetFormatFromFileName(const AFileName: TFileName;
out AFormatID: TsSpreadFormatID): Boolean;
var
suffix: String;
fileformats: TsSpreadFormatIDArray;
begin
fileFormats := GetSpreadFormatsFromFileName(faRead, AFileName, ord(sfExcel8));
Result := (Length(fileFormats) > 0) and (fileFormats[0] <= sfidUnknown);
if Result then AFormatID := fileFormats[0];
end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Determines the spreadsheet type from the file type extension Determines the spreadsheet type from the file type extension
@param AFileName Name of the file to be considered @param AFileName Name of the file to be considered
@param SheetType File format found from analysis of the extension (output) @param SheetType Built-in file format found from analysis of the extension
@return True if the file matches any of the known formats, false otherwise (output)
@return True if the file matches any of the built-in formats, false otherwise
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function GetFormatFromFileName(const AFileName: TFileName; function GetFormatFromFileName(const AFileName: TFileName;
out SheetType: TsSpreadsheetFormat): Boolean; out SheetType: TsSpreadsheetFormat): Boolean;
var var
suffix: String; fmtID: TsSpreadFormatID;
begin begin
Result := GetFormatFromFileName(AFileName, fmtID);
if Result and (fmtID < 0) then Result := false;
end;
{
Result := true; Result := true;
suffix := Lowercase(ExtractFileExt(AFileName)); suffix := Lowercase(ExtractFileExt(AFileName));
case suffix of case suffix of
@ -1113,7 +1139,8 @@ begin
else Result := False; else Result := False;
end; end;
end; end;
*) }
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Helper function to reduce typing: "if a conditions is true return the first Helper function to reduce typing: "if a conditions is true return the first
number format, otherwise return the second format" number format, otherwise return the second format"