From 390b0539f12bbef77a825f708c31c4c6b86833a3 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 8 Oct 2014 09:23:34 +0000 Subject: [PATCH] fpspreadsheet: Move some more translatable strings to fpsStrings unit. Some clean-up & cosmetics. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3640 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/fpsopendocument.pas | 106 ++----------------- components/fpspreadsheet/fpspreadsheet.pas | 9 +- components/fpspreadsheet/fpsstrings.pas | 17 ++- components/fpspreadsheet/wikitable.pas | 9 +- components/fpspreadsheet/xlsbiff2.pas | 45 +------- components/fpspreadsheet/xlsbiff5.pas | 33 ++---- components/fpspreadsheet/xlsbiff8.pas | 16 +-- components/fpspreadsheet/xlscommon.pas | 88 +++------------ components/fpspreadsheet/xlsxooxml.pas | 58 +++------- 9 files changed, 76 insertions(+), 305 deletions(-) diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 90498a12d..430d92b08 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -194,7 +194,7 @@ type implementation uses - StrUtils, Variants, fpsStreams, fpsExprParser; + StrUtils, Variants, fpsStrings, fpsStreams, fpsExprParser; const { OpenDocument general XML constants } @@ -2680,82 +2680,6 @@ begin '' + '' ); - - - - (* - lNumFmtCode := WriteNumFormatsXMLAsString; - - lColStylesCode := WriteColStylesXMLAsString; - if lColStylesCode = '' then lColStylesCode := - ' ' + LineEnding + - ' ' + LineEnding + - ' ' + LineEnding; - - lRowStylesCode := WriteRowStylesXMLAsString; - if lRowStylesCode = '' then lRowStylesCode := - ' ' + LineEnding + - ' ' + LineEnding + - ' ' + LineEnding; - - lCellStylesCode := WriteCellStylesXMLAsString; - - FContent := - XML_HEADER + LineEnding + - '' + LineEnding + - ' ' + LineEnding + - - // Fonts - ' ' + LineEnding + - ' ' + WriteFontNamesXMLAsString + LineEnding + -// ' ' + LineEnding + - ' ' + LineEnding + - - // Automatic styles - ' ' + LineEnding + - lNumFmtCode + - lColStylesCode + - lRowStylesCode + - ' ' + LineEnding + - ' ' + LineEnding + - ' ' + LineEnding + - - // Automatically Generated Styles - lCellStylesCode + - ' ' + LineEnding + - - // Body - ' ' + LineEnding + - ' ' + LineEnding; - - // Write all worksheets - for i := 0 to Workbook.GetWorksheetCount - 1 do - WriteWorksheet(Workbook.GetWorksheetByIndex(i)); - - FContent := FContent + - ' ' + LineEnding + - ' ' + LineEnding + - ''; - *) end; procedure TsSpreadOpenDocWriter.WriteWorksheet(AStream: TStream; @@ -2892,7 +2816,7 @@ begin break; end; if stylename = '' then - raise Exception.Create('Column style not found.'); + raise Exception.Create(rsColumnStyleNotFound); // Determine value for "number-columns-repeated" colsRepeated := 1; @@ -3008,7 +2932,7 @@ begin end; end; if styleName = '' then - raise Exception.Create('Row style not found.'); + raise Exception.Create(rsRowStyleNotFound); end; // Take care of empty rows above the first row @@ -3250,15 +3174,6 @@ begin end; end; - (* -procedure TsSpreadOpenDocWriter.WriteToStream(AStream: TStream); -begin - Unused(AStream); - // Not supported at the moment - raise Exception.Create('TsSpreadOpenDocWriter.WriteToStream not supported'); -end; - *) - { Writes an empty cell } @@ -3381,8 +3296,6 @@ begin Workbook.GetPaletteColorAsHTMLStr(AFormat.BorderStyles[cbDiagDown].Color) ]); end; - - end; function TsSpreadOpenDocWriter.WriteDefaultFontXMLAsString: String; @@ -3582,7 +3495,7 @@ begin end; end; if styleName = '' then - raise Exception.Create('Row style not found.'); + raise Exception.Create(rsRowStyleNotFound); end; // No empty rows allowed here for the moment! @@ -3761,7 +3674,7 @@ begin if ACell^.CalcState=csCalculated then AppendToStream(AStream, Format( '' + - valueStr + + valueStr + '', [ formula, valuetype, value, lStyle, spannedStr ])) @@ -3813,7 +3726,7 @@ begin str := AValue; if not ValidXMLText(str) then Workbook.AddErrorMsg( - 'Invalid character(s) in cell %s.', [ + rsInvalidCharacterInCell, [ GetCellString(ARow, ACol) ]); @@ -3879,13 +3792,6 @@ begin valType, StrValue, lStyle, spannedStr, DisplayStr ])); - { - - - '' + - '' + DisplayStr + '' + - ''); - } end; {******************************************************************* diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index 8c5be5b05..217e8570b 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -5945,9 +5945,9 @@ begin if valid then WriteToFile(AFileName, SheetType, AOverwriteExisting) else - raise Exception.Create(Format( - '[TsWorkbook.WriteToFile] Attempt to save a spreadsheet by extension, ' + - 'but the extension %s is not valid.', [ExtractFileExt(AFileName)])); + raise Exception.Create(Format(rsInvalidExtension, [ + ExtractFileExt(AFileName) + ])); end; {@@ ---------------------------------------------------------------------------- @@ -6643,7 +6643,8 @@ end; @param AColorIndex Palette index of the color to be replaced @param AColorValue Number containing the rgb components of the new color -------------------------------------------------------------------------------} -procedure TsWorkbook.SetPaletteColor(AColorIndex: TsColor; AColorValue: TsColorValue); +procedure TsWorkbook.SetPaletteColor(AColorIndex: TsColor; + AColorValue: TsColorValue); begin if (AColorIndex >= 0) and (AColorIndex < GetPaletteSize) then begin diff --git a/components/fpspreadsheet/fpsstrings.pas b/components/fpspreadsheet/fpsstrings.pas index 8acba7624..c746c6f70 100644 --- a/components/fpspreadsheet/fpsstrings.pas +++ b/components/fpspreadsheet/fpsstrings.pas @@ -21,6 +21,8 @@ resourcestring rsTooManyPaletteColors = 'This workbook contains more colors (%d) than ' + 'supported by the file format (%d). The additional colors are replaced by '+ 'the best-matching palette colors.'; + rsInvalidExtension = 'Attempting to save a spreadsheet by extension, ' + + 'but the extension %s is not valid.'; rsInvalidFontIndex = 'Invalid font index'; rsInvalidNumberFormat = 'Trying to use an incompatible number format.'; rsInvalidDateTimeFormat = 'Trying to use an incompatible date/time format.'; @@ -33,8 +35,21 @@ resourcestring rsCircularReference = 'Circular reference found when calculating worksheet formulas'; rsFileNotFound = 'File "%s" not found.'; rsInvalidWorksheetName = '"%s" is not a valid worksheet name.'; + rsDefectiveInternalStructure = 'Defective internal structure of %s file.'; + rsUnknownDataType = 'Unknown data type.'; + rsUnknownErrorType = 'Unknown error type.'; + rsTruncateTooLongCellText = 'Text value exceeds %d character limit in cell %s '+ + 'and has been truncated.'; + rsColumnStyleNotFound = 'Column style not found.'; + rsRowStyleNotFound = 'Row style not found.'; + rsInvalidCharacterInCell = 'Invalid character(s) in cell %s.'; + rsUTF8TextExpectedButANSIFoundInCell = 'Expected UTF8 text but probably ANSI '+ + 'text found in cell %s.'; + rsIndexInSSTOutOfRange = 'Index %d in SST out of range (0-%d).'; - rsTRUE = 'TRUE'; + + + rsTRUE = 'TRUE'; // wp: Do we really want to translate these strings? rsFALSE = 'FALSE'; rsErrEmptyIntersection = '#NULL!'; rsErrDivideByZero = '#DIV/0!'; diff --git a/components/fpspreadsheet/wikitable.pas b/components/fpspreadsheet/wikitable.pas index 1263c3f1e..3183905ce 100644 --- a/components/fpspreadsheet/wikitable.pas +++ b/components/fpspreadsheet/wikitable.pas @@ -107,9 +107,13 @@ type implementation -{ TsWikiTableNumFormatList } +uses + fpsStrings; +{ TsWikiTableNumFormatList } +//... + { TWikiTableTokenizer } constructor TWikiTableTokenizer.Create; @@ -456,8 +460,7 @@ begin // Check for invalid characters if not ValidXMLText(lCurStr, false) then - Workbook.AddErrorMsg( - 'Invalid character(s) in cell %s.', [ + Workbook.AddErrorMsg(rsInvalidCharacterInCell, [ GetCellString(i, j) ]); diff --git a/components/fpspreadsheet/xlsbiff2.pas b/components/fpspreadsheet/xlsbiff2.pas index cfe2c8884..8c6ebf4c6 100755 --- a/components/fpspreadsheet/xlsbiff2.pas +++ b/components/fpspreadsheet/xlsbiff2.pas @@ -158,7 +158,7 @@ var implementation uses - Math, fpsNumFormatParser; + Math, fpsStrings, fpsNumFormatParser; const { Excel record IDs } @@ -559,7 +559,6 @@ var XF: Word; ok: Boolean; formulaResult: Double = 0.0; -// rpnFormula: TsRPNFormula; Data: array [0..7] of byte; dt: TDateTime; nf: TsNumberFormat; @@ -1010,7 +1009,7 @@ begin // Carefully check the index if (lIndex < 0) or (lIndex > Length(FFormattingStyles)) then - raise Exception.Create('[TsSpreadBIFF2Writer.WriteXFIndex] Invalid Index, this should not happen!'); + raise Exception.Create('[TsSpreadBIFF2Writer.WriteXFIndex] Invalid index, this should not happen!'); Result := FFormattingStyles[lIndex].Row; end; end; @@ -1155,17 +1154,6 @@ begin { Write out } AStream.WriteBuffer(rec, SizeOf(rec)); - - (* - { BIFF Record header } - AStream.WriteWord(WordToLE(INT_EXCEL_ID_COLWIDTH)); // BIFF record header - AStream.WriteWord(WordToLE(4)); // Record size - AStream.WriteByte(ACol^.Col); // start column - AStream.WriteByte(ACol^.Col); // end column - { calculate width to be in units of 1/256 of pixel width of character "0" } - w := round(ACol^.Width * 256); - AStream.WriteWord(WordToLE(w)); // write width - *) end; end; @@ -1211,7 +1199,6 @@ begin AStream.WriteBuffer(rec, SizeOf(rec)); end; - { Writes an Excel 2 IXFE record This record contains the "real" XF index if it is > 62. @@ -1554,16 +1541,6 @@ begin { Clean up } SetLength(buf, 0); - - (* - { BIFF Record header } - AStream.WriteWord(WordToLE(INT_EXCEL_ID_FORMAT)); - AStream.WriteWord(WordToLE(1 + len)); - - { Format string } - AStream.WriteByte(len); // AnsiString, char count in 1 byte - AStream.WriteBuffer(s[1], len); // String data - *) end; procedure TsSpreadBIFF2Writer.WriteFormatCount(AStream: TStream); @@ -1639,7 +1616,6 @@ begin { Write following STRING record if formula result is a non-empty string } if (ACell^.ContentType = cctUTF8String) and (ACell^.UTF8StringValue <> '') then WriteStringRecord(AStream, ACell^.UTF8StringValue); - end; { Writes the identifier for an RPN function with fixed argument count and @@ -1756,19 +1732,6 @@ begin { Write out } AStream.WriteBuffer(rec, Sizeof(rec)); - - (* - { BIFF Record header } - AStream.WriteWord(WordToLE(INT_EXCEL_ID_BLANK)); - AStream.WriteWord(WordToLE(7)); - - { BIFF Record data } - AStream.WriteWord(WordToLE(ARow)); - AStream.WriteWord(WordToLE(ACol)); - - { BIFF2 Attributes } - WriteCellFormatting(AStream, ACell, xf); - *) end; {******************************************************************* @@ -1807,9 +1770,7 @@ begin // Rather than lose data when reading it, let the application programmer deal // with the problem or purposefully ignore it. AnsiText := Copy(AnsiText, 1, MAXBYTES); - Workbook.AddErrorMsg( - 'Text value exceeds %d character limit in cell %s. ' + - 'Text has been truncated.', [ + Workbook.AddErrorMsg(rsTruncateTooLongCellText, [ MAXBYTES, GetCellString(ARow, ACol) ]); end; diff --git a/components/fpspreadsheet/xlsbiff5.pas b/components/fpspreadsheet/xlsbiff5.pas index 094d2d942..f5bd3deb6 100755 --- a/components/fpspreadsheet/xlsbiff5.pas +++ b/components/fpspreadsheet/xlsbiff5.pas @@ -215,7 +215,7 @@ var implementation uses - fpsStreams; + fpsStrings, fpsStreams; const { Excel record IDs } @@ -448,28 +448,7 @@ begin SetLength(Boundsheets, 0); end; - (* -{******************************************************************* -* TsSpreadBIFF5Writer.WriteBlank -* -* DESCRIPTION: Writes the record for an empty cell -* -*******************************************************************} -procedure TsSpreadBIFF5Writer.WriteBlank(AStream: TStream; - const ARow, ACol: Cardinal; ACell: PCell); -begin - { BIFF Record header } - AStream.WriteWord(WordToLE(INT_EXCEL_ID_BLANK)); - AStream.WriteWord(WordToLE(6)); - { BIFF Record data } - AStream.WriteWord(WordToLE(ARow)); - AStream.WriteWord(WordToLE(ACol)); - - { Index to XF record } - WriteXFIndex(AStream, ACell); -end; - *) {******************************************************************* * TsSpreadBIFF5Writer.WriteBOF () * @@ -795,7 +774,9 @@ begin // Bad formatted UTF8String (maybe ANSI?) if Length(AValue) <> 0 then begin //It was an ANSI string written as UTF8 quite sure, so raise exception. - Raise Exception.CreateFmt('Expected UTF8 text but probably ANSI text found in cell [%d,%d]',[ARow,ACol]); + Raise Exception.CreateFmt(rsUTF8TextExpectedButANSIFoundInCell, [ + GetCellString(ARow, ACol) + ]); end; Exit; end; @@ -804,9 +785,7 @@ begin // Rather than lose data when reading it, let the application programmer deal // with the problem or purposefully ignore it. AnsiValue := Copy(AnsiValue, 1, MAXBYTES); - Workbook.AddErrorMsg( - 'Text value exceeds %d character limit in cell %s. ' + - 'Text has been truncated.', [ + Workbook.AddErrorMsg(rsInvalidCharacterInCell, [ MAXBYTES, GetCellString(ARow, ACol) ]); end; @@ -1345,7 +1324,7 @@ begin OLEStorage.ReadOLEFile(AFileName, OLEDocument); // Check if the operation succeded - if MemStream.Size = 0 then raise Exception.Create('FPSpreadsheet: Reading the OLE document failed'); + if MemStream.Size = 0 then raise Exception.Create('[TsSpreadBIFF5Reader.ReadFromFile] Reading of OLE document failed'); // Rewind the stream and read from it MemStream.Position := 0; diff --git a/components/fpspreadsheet/xlsbiff8.pas b/components/fpspreadsheet/xlsbiff8.pas index 363df2354..00e17bcc2 100755 --- a/components/fpspreadsheet/xlsbiff8.pas +++ b/components/fpspreadsheet/xlsbiff8.pas @@ -226,7 +226,7 @@ var implementation uses - Math, fpsStreams, fpsExprParser; + Math, fpsStrings, fpsStreams, fpsExprParser; const { Excel record IDs } @@ -930,7 +930,7 @@ begin // Badly formatted UTF8String (maybe ANSI?) if Length(AValue)<>0 then begin //Quite sure it was an ANSI string written as UTF8, so raise exception. - Raise Exception.CreateFmt('Expected UTF8 text but probably ANSI text found in cell [%d,%d]',[ARow,ACol]); + raise Exception.CreateFmt(rsUTF8TextExpectedButANSIFoundInCell, [GetCellString(ARow,ACol)]); end; Exit; end; @@ -939,9 +939,7 @@ begin // Rather than lose data when reading it, let the application programmer deal // with the problem or purposefully ignore it. SetLength(WideValue, MAXBYTES); //may corrupt the string (e.g. in surrogate pairs), but... too bad. - Workbook.AddErrorMsg( - 'Text value exceeds %d character limit in cell %s. ' + - 'Text has been truncated.', [ + Workbook.AddErrorMsg(rsTruncateTooLongCellText, [ MAXBYTES, GetCellString(ARow, ACol) ]); end; @@ -1528,7 +1526,7 @@ begin // Can't be shared with BIFF5 because of the parameter "Workbook" !!!) // Check if the operation succeded - if MemStream.Size = 0 then raise Exception.Create('FPSpreadsheet: Reading the OLE document failed'); + if MemStream.Size = 0 then raise Exception.Create('[TsSpreadBIFF8Reader.ReadFromFile] Reading of OLE document failed'); // Rewind the stream and read from it MemStream.Position := 0; @@ -1604,7 +1602,7 @@ begin { Save the data } if FIsVirtualMode then begin - InitCell(ARow, ACol, FVirtualCell); // "virtual" cell + InitCell(ARow, ACol, FVirtualCell); // "virtual" cell cell := @FVirtualCell; end else cell := FWorksheet.GetCell(ARow, ACol); // "real" cell @@ -1866,7 +1864,9 @@ begin SSTIndex := DWordLEToN(rec.SSTIndex); if SizeInt(SSTIndex) >= FSharedStringTable.Count then begin - Raise Exception.CreateFmt('Index %d in SST out of range (0-%d)',[Integer(SSTIndex),FSharedStringTable.Count-1]); + raise Exception.CreateFmt(rsIndexInSSTOutOfRange, [ + Integer(SSTIndex),FSharedStringTable.Count-1 + ]); end; { Create cell } diff --git a/components/fpspreadsheet/xlscommon.pas b/components/fpspreadsheet/xlscommon.pas index dc6931180..d51a435c2 100644 --- a/components/fpspreadsheet/xlscommon.pas +++ b/components/fpspreadsheet/xlscommon.pas @@ -70,22 +70,22 @@ const INT_FONT_WEIGHT_BOLD = $02BC; { CODEPAGE record constants } - WORD_ASCII = 367; - WORD_UTF_16 = 1200; // BIFF 8 - WORD_CP_1250_Latin2 = 1250; - WORD_CP_1251_Cyrillic = 1251; - WORD_CP_1252_Latin1 = 1252; // BIFF4-BIFF5 - WORD_CP_1253_Greek = 1253; - WORD_CP_1254_Turkish = 1254; - WORD_CP_1255_Hebrew = 1255; - WORD_CP_1256_Arabic = 1256; - WORD_CP_1257_Baltic = 1257; - WORD_CP_1258_Vietnamese = 1258; + WORD_ASCII = 367; + WORD_UTF_16 = 1200; // BIFF 8 + WORD_CP_1250_Latin2 = 1250; + WORD_CP_1251_Cyrillic = 1251; + WORD_CP_1252_Latin1 = 1252; // BIFF4-BIFF5 + WORD_CP_1253_Greek = 1253; + WORD_CP_1254_Turkish = 1254; + WORD_CP_1255_Hebrew = 1255; + WORD_CP_1256_Arabic = 1256; + WORD_CP_1257_Baltic = 1257; + WORD_CP_1258_Vietnamese = 1258; WORD_CP_1258_Latin1_BIFF2_3 = 32769; // BIFF2-BIFF3 { DATEMODE record, 5.28 } - DATEMODE_1900_BASE = 1; //1/1/1900 minus 1 day in FPC TDateTime - DATEMODE_1904_BASE = 1462; //1/1/1904 in FPC TDateTime + DATEMODE_1900_BASE = 1; //1/1/1900 minus 1 day in FPC TDateTime + DATEMODE_1904_BASE = 1462; //1/1/1904 in FPC TDateTime { WINDOW1 record constants - BIFF5-BIFF8 } MASK_WINDOW1_OPTION_WINDOW_HIDDEN = $0001; @@ -1786,25 +1786,7 @@ begin end else Result := AColor; end; - (* -function TsSpreadBIFFWriter.FormulaElementKindToExcelTokenID( - AElementKind: TFEKind; out ASecondaryID: Word): Word; -begin - if AElementKind = fekFunc then - if (AElementKind >= Low(TFuncTokens)) and (AElementKind <= High(TFuncTokens)) - then begin - if FixedParamCount(AElementKind) then - Result := INT_EXCEL_TOKEN_FUNC_V - else - Result := INT_EXCEL_TOKEN_FUNCVAR_V; - ASecondaryID := TokenIDs[AElementKind]; - end - else begin - Result := TokenIDs[AElementKind]; - ASecondaryID := 0; - end; -end; - *) + procedure TsSpreadBIFFWriter.GetLastRowCallback(ACell: PCell; AStream: TStream); begin Unused(AStream); @@ -1855,18 +1837,6 @@ begin { Write out } AStream.WriteBuffer(rec, SizeOf(rec)); - (* - { BIFF Record header } - AStream.WriteWord(WordToLE(INT_EXCEL_ID_BLANK)); - AStream.WriteWord(WordToLE(6)); - - { Row and column index } - AStream.WriteWord(WordToLE(ARow)); - AStream.WriteWord(WordToLE(ACol)); - - { Index to XF record, according to formatting } - WriteXFIndex(AStream, ACell); - *) end; procedure TsSpreadBIFFWriter.WriteCodepage(AStream: TStream; @@ -1933,20 +1903,6 @@ begin { Write out } AStream.WriteBuffer(rec, SizeOf(rec)); - - (* - { BIFF Record header } - AStream.WriteWord(WordToLE(INT_EXCEL_ID_COLINFO)); // BIFF record header - AStream.WriteWord(WordToLE(12)); // Record size - AStream.WriteWord(WordToLE(ACol^.Col)); // start column - AStream.WriteWord(WordToLE(ACol^.Col)); // end column - { calculate width to be in units of 1/256 of pixel width of character "0" } - w := round(ACol^.Width * 256); - AStream.WriteWord(WordToLE(w)); // write width - AStream.WriteWord(15); // XF record, ignored - AStream.WriteWord(0); // option flags, ignored - AStream.WriteWord(0); // "not used" - *) end; end; @@ -2062,22 +2018,6 @@ begin AStream.WriteBuffer(rec, sizeof(Rec)); end; - (* - - { BIFF Record header } - AStream.WriteWord(WordToLE(INT_EXCEL_ID_NUMBER)); - AStream.WriteWord(WordToLE(14)); - - { BIFF Record data } - AStream.WriteWord(WordToLE(ARow)); - AStream.WriteWord(WordToLE(ACol)); - - { Index to XF record } - WriteXFIndex(AStream, ACell); - - { IEE 754 floating-point value } - AStream.WriteBuffer(AValue, 8); -end; *) procedure TsSpreadBIFFWriter.WritePalette(AStream: TStream); var diff --git a/components/fpspreadsheet/xlsxooxml.pas b/components/fpspreadsheet/xlsxooxml.pas index 6e0615afe..0d2d6caac 100755 --- a/components/fpspreadsheet/xlsxooxml.pas +++ b/components/fpspreadsheet/xlsxooxml.pas @@ -171,7 +171,8 @@ type implementation uses - variants, fileutil, strutils, math, lazutf8, fpsStreams, fpsNumFormatParser; + variants, fileutil, strutils, math, lazutf8, + fpsStrings, fpsStreams, fpsNumFormatParser; const { OOXML general XML constants } @@ -735,9 +736,9 @@ begin else if dataStr = '#N/A' then AWorksheet.WriteErrorValue(cell, errArgError) else - raise Exception.Create('unknown error type'); + raise Exception.Create(rsUnknownErrorType); end else - raise Exception.Create('Unknown data type'); + raise Exception.Create(rsUnknownDataType); if FIsVirtualMode then Workbook.OnReadCellData(Workbook, rowIndex, colIndex, cell); @@ -960,33 +961,11 @@ begin colorNode := patternNode.FirstChild; while Assigned(colorNode) do begin nodeName := colorNode.NodeName; - if nodeName = 'fgColor' then begin - fgclr := ReadColor(colorNode); - { - s := GetAttrValue(colorNode, 'rgb'); - if s <> '' then - fgclr := FWorkbook.AddColorToPalette(HTMLColorStrToColor('#' + s)) - else begin - s := GetAttrValue(colorNode, 'indexed'); - if s <> '' then - fgclr := StrToInt(s); - end; - } - end + if nodeName = 'fgColor' then + fgclr := ReadColor(colorNode) else - if nodeName = 'bgColor' then begin + if nodeName = 'bgColor' then bgclr := ReadColor(colorNode); - { - s := GetAttrValue(colorNode, 'rgb'); - if s <> '' then - bgclr := FWorkbook.AddColorToPalette(HTMLColorStrToColor('#' + s)) - else begin - s := GetAttrValue(colorNode, 'indexed'); - if s <> '' then - bgclr := StrToInt(s); - end; - } - end; colorNode := colorNode.NextSibling; end; @@ -1022,8 +1001,8 @@ begin fntStyles := fnt.Style; fntColor := fnt.Color; end else begin - fntName := 'Arial'; - fntSize := 10; + fntName := DEFAULTFONTNAME; + fntSize := DEFAULTFONTSIZE; fntStyles := []; fntColor := scBlack; end; @@ -1272,7 +1251,6 @@ begin sheetName := GetAttrValue(node, 'name'); //sheetId := GetAttrValue(node, 'sheetId'); AList.Add(sheetName); -// AList.AddObject(sheetName, pointer(PtrInt(StrToInt(sheetId)))); node := node.NextSibling; end; end; @@ -1465,7 +1443,7 @@ begin // process the workbook.xml file if not FileExists(FilePath + OOXML_PATH_XL_WORKBOOK) then - raise Exception.Create('Defective internal structure of xlsx file'); + raise Exception.CreateFmt(rsDefectiveInternalStructure, ['xlsx']); ReadXMLFile(Doc, FilePath + OOXML_PATH_XL_WORKBOOK); DeleteFile(FilePath + OOXML_PATH_XL_WORKBOOK); ReadFileVersion(Doc.DocumentElement.FindNode('fileVersion')); @@ -2047,7 +2025,6 @@ begin AppendToStream(AStream, Format( '' + '' + -// '', [ showGridLines, showHeaders ])) @@ -2714,14 +2691,12 @@ begin if Length(AValue) > MAXBYTES then begin ResultingValue := Copy(AValue, 1, MAXBYTES); //may chop off multicodepoint UTF8 characters but well... - Workbook.AddErrorMsg( - 'Text value exceeds %d character limit in cell %s. ' + - 'Text has been truncated.', [ + Workbook.AddErrorMsg(rsTruncateTooLongCellText, [ MAXBYTES, GetCellString(ARow, ACol) ]); end else - ResultingValue:=AValue; + ResultingValue := AValue; if not ValidXMLText(ResultingValue) then Workbook.AddErrorMsg( @@ -2740,15 +2715,6 @@ begin '%d', [CellPosText, lStyleIndex, FSharedStringsCount])); inc(FSharedStringsCount); - - { - //todo: keep a log of errors and show with an exception after writing file or something. - We can't just do the following - - if TextTooLong then - Raise Exception.CreateFmt('Text value exceeds %d character limit in cell [%d,%d]. Text has been truncated.',[MaxBytes,ARow,ACol]); - because the file wouldn't be written. - } end; {