fpspreadsheet: Move check for sheet name length to writer -> Sheet names can be any length now. But saving to Excel will abort if there are more than 31 characters.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4656 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-05-20 21:00:20 +00:00
parent 56aee895f3
commit 8ed5356be2
11 changed files with 44 additions and 2 deletions

View File

@ -7861,10 +7861,12 @@ begin
if (AName = '') then
exit;
{ wp: the length restriction has been moved to the writer...
// Length must be less than 31 characters
if UTF8Length(AName) > 31 then
exit;
}
// Name must not contain any of the INVALID_CHARS
for i:=0 to High(INVALID_CHARS) do
if UTF8Pos(INVALID_CHARS[i], AName) > 0 then

View File

@ -184,7 +184,7 @@ type
implementation
uses
Math,
Math, LazUTF8,
fpsStrings, fpsUtils, fpsNumFormat, fpsStreams, fpsRegFileFormats;
@ -208,6 +208,7 @@ begin
FLimitations.MaxColCount := 256;
FLimitations.MaxRowCount := 65536;
FLimitations.MaxPaletteSize := MaxInt;
FLimitations.MaxSheetnameLength := MaxInt;
end;
{@@ ----------------------------------------------------------------------------
@ -230,6 +231,8 @@ end;
procedure TsBasicSpreadWriter.CheckLimitations;
var
lastCol, lastRow: Cardinal;
i: Integer;
sheet: TsWorksheet;
begin
Workbook.GetLastRowColIndex(lastRow, lastCol);
@ -240,6 +243,18 @@ begin
// Check column count
if lastCol >= FLimitations.MaxColCount then
Workbook.AddErrorMsg(rsMaxColsExceeded, [lastCol+1, FLimitations.MaxColCount]);
// Check worksheet names
for i:=0 to Workbook.GetWorksheetCount-1 do
begin
sheet := Workbook.GetWorksheetByIndex(i);
if UTF8Length(sheet.Name) > FLimitations.MaxSheetNameLength then
// Worksheet name is too long.
// We abort saving here because it is not safe to chop the sheet name
// to its allowed length - it may be used as a reference in formulas.
raise Exception.CreateFmt(rsWriteError_WorksheetNameTooLong,
[sheet.Name, FLimitations.MaxSheetNameLength]);
end;
end;

View File

@ -37,6 +37,8 @@ resourcestring
'the best-matching palette colors.';
rsTruncateTooLongCellText = 'Text value exceeds the %d character limit in ' +
'cell %s and has been truncated.';
rsWriteError_WorksheetNameTooLong = 'File cannot be written because ' +
'the name of worksheet "%0:s" is too long (max %1:d characters).';
// Cells
rsInvalidCharacterInCell = 'Invalid character(s) in cell %s.';

View File

@ -44,6 +44,7 @@ type
MaxRowCount: Cardinal;
MaxColCount: Cardinal;
MaxPaletteSize: Integer;
MaxSheetNameLength: Integer;
end;
const

View File

@ -412,6 +412,10 @@ msgstr "Arbeitsblatt \"%s\" nicht gefunden"
msgid "Worksheet not found."
msgstr "Arbeitsblatt nicht gefunden."
#: fpsstrings.rswriteerror_worksheetnametoolong
msgid "File cannot be written because the name of worksheet \"%0:s\" is too long (max %1:d characters)."
msgstr "Die Datei kann nicht geschrieben werden, weil der Name des Arbeitsblattes \"%0s:s\" zu lang ist (höchstens %1:d Zeichen)."
#: fpsstrings.rsyellow
msgid "yellow"
msgstr "gelb"

View File

@ -401,6 +401,10 @@ msgstr ""
msgid "Worksheet not found."
msgstr ""
#: fpsstrings.rswriteerror_worksheetnametoolong
msgid "File cannot be written because the name of worksheet \"%0:s\" is too long (max %1:d characters)."
msgstr ""
#: fpsstrings.rsyellow
msgid "yellow"
msgstr "keltainen"

View File

@ -411,6 +411,10 @@ msgstr "A(z) \"%s\" munkalap nem található."
msgid "Worksheet not found."
msgstr "A munkalap nem található."
#: fpsstrings.rswriteerror_worksheetnametoolong
msgid "File cannot be written because the name of worksheet \"%0:s\" is too long (max %1:d characters)."
msgstr ""
#: fpsstrings.rsyellow
msgid "yellow"
msgstr "sárga"

View File

@ -401,6 +401,10 @@ msgstr ""
msgid "Worksheet not found."
msgstr ""
#: fpsstrings.rswriteerror_worksheetnametoolong
msgid "File cannot be written because the name of worksheet \"%0:s\" is too long (max %1:d characters)."
msgstr ""
#: fpsstrings.rsyellow
msgid "yellow"
msgstr ""

View File

@ -401,6 +401,10 @@ msgstr "Лист таблицы \"%s\" не найден."
msgid "Worksheet not found."
msgstr "Лист таблицы не найден"
#: fpsstrings.rswriteerror_worksheetnametoolong
msgid "File cannot be written because the name of worksheet \"%0:s\" is too long (max %1:d characters)."
msgstr ""
#: fpsstrings.rsyellow
msgid "yellow"
msgstr "жёлтый"

View File

@ -2853,6 +2853,7 @@ begin
FLimitations.MaxColCount := 256;
FLimitations.MaxRowCount := 65536;
FLimitations.MaxPaletteSize := 64;
FLimitations.MaxSheetNameLength := 31;
// Initial base date in case it won't be set otherwise.
// Use 1900 to get a bit more range between 1900..1904.

View File

@ -2220,6 +2220,7 @@ begin
// http://en.wikipedia.org/wiki/List_of_spreadsheet_software#Specifications
FLimitations.MaxColCount := 16384;
FLimitations.MaxRowCount := 1048576;
FLimitations.MaxSheetNameLength := 31;
end;