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
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,
stored in the TsSpreadFormatData class and returned as function result.
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.');
fmt := TsSpreadFormatData.Create(ord(AFormat), AReaderClass, AWriterClass,
AFormatName, ATechnicalName, AFileExtensions); //, ACanReadFromClipboard, ACanWriteToClipboard);
AFormatName, ATechnicalName, AFileExtensions);
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;
end;
Result := fmt.FormatID;
end;

View File

@ -105,8 +105,10 @@ function TryStrToErrorValue(AErrorStr: String; out AErr: TsErrorValue): boolean;
//function GetFileFormatName(AFormat: TsSpreadsheetFormat): string;
//function GetFileFormatExt(AFormat: TsSpreadsheetFormat): String;
//function GetFormatFromFileName(const AFileName: TFileName;
// out SheetType: TsSpreadsheetFormat): Boolean;
function GetFormatFromFileName(const AFileName: TFileName;
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;
@ -191,7 +193,7 @@ var
implementation
uses
Math, lazutf8, lazfileutils, fpsStrings;
Math, lazutf8, lazfileutils, fpsStrings, fpsRegFileFormats;
{******************************************************************************}
{ Endianess helper functions }
@ -1087,19 +1089,43 @@ begin
else raise Exception.Create(rsUnknownSpreadsheetFormat);
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
@param AFileName Name of the file to be considered
@param SheetType File format found from analysis of the extension (output)
@return True if the file matches any of the known formats, false otherwise
@param SheetType Built-in file format found from analysis of the extension
(output)
@return True if the file matches any of the built-in formats, false otherwise
-------------------------------------------------------------------------------}
function GetFormatFromFileName(const AFileName: TFileName;
out SheetType: TsSpreadsheetFormat): Boolean;
var
suffix: String;
fmtID: TsSpreadFormatID;
begin
Result := GetFormatFromFileName(AFileName, fmtID);
if Result and (fmtID < 0) then Result := false;
end;
{
Result := true;
suffix := Lowercase(ExtractFileExt(AFileName));
case suffix of
@ -1113,7 +1139,8 @@ begin
else Result := False;
end;
end;
*)
}
{@@ ----------------------------------------------------------------------------
Helper function to reduce typing: "if a conditions is true return the first
number format, otherwise return the second format"