diff --git a/components/fpspreadsheet/examples/read_write/hyperlinkdemo/collectlinks.lpr b/components/fpspreadsheet/examples/read_write/hyperlinkdemo/collectlinks.lpr index 74282ee6a..7902b1cf1 100644 --- a/components/fpspreadsheet/examples/read_write/hyperlinkdemo/collectlinks.lpr +++ b/components/fpspreadsheet/examples/read_write/hyperlinkdemo/collectlinks.lpr @@ -31,7 +31,7 @@ var begin // Just for the demo: create the file "source.xls". It contains hyperlinks to - // some the "test" files created in the XXXXdemo projects + // some of the "test" files created in the XXXXdemo projects Write('Creating source workbook...'); srcWorkbook := TsWorkbook.Create; try diff --git a/components/fpspreadsheet/examples/read_write/hyperlinkdemo/readme.txt b/components/fpspreadsheet/examples/read_write/hyperlinkdemo/readme.txt index dd661beee..1ea46e025 100644 --- a/components/fpspreadsheet/examples/read_write/hyperlinkdemo/readme.txt +++ b/components/fpspreadsheet/examples/read_write/hyperlinkdemo/readme.txt @@ -1,5 +1,5 @@ -This sample project demonstrates how to use fpspreadsheet can follow the hyperlinks +This sample project demonstrates how fpspreadsheet can follow the hyperlinks to other spreadsheet files and copy the linked sheets to a new document. -Please run the write demos ooxmldemo/ooxmlwrite and excel8demp/excel8write before -running this project in order to generate required spreadsheet files. +Please run the write demos ../ooxmldemo/ooxmlwrite and ../excel8demo/excel8write +before running this project in order to generate required spreadsheet files. diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 8639f827a..bfb41514a 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -50,12 +50,6 @@ type { TsSpreadOpenDocNumFormatParser } TsSpreadOpenDocNumFormatParser = class(TsNumFormatParser) - { - private - function BuildCurrencyXMLAsString(ASection: Integer): String; - function BuildDateTimeXMLAsString(ASection: Integer; - out AIsTimeOnly, AIsInterval: Boolean): String; - } protected function BuildXMLAsStringFromSection(ASection: Integer; AFormatName: String): String; @@ -71,7 +65,6 @@ type FColumnList: TFPList; FRowStyleList: TFPList; FRowList: TFPList; -// FVolatileNumFmtList: TStringList; FDateMode: TDateMode; // Applies internally stored column widths to current worksheet procedure ApplyColWidths; @@ -298,194 +291,10 @@ type *) -{------------------------------------------------------------------------------} +{******************************************************************************} { TsSpreadOpenDocNumFormatParser } -{------------------------------------------------------------------------------} +{******************************************************************************} - (* -function TsSpreadOpenDocNumFormatParser.BuildCurrencyXMLAsString(ASection: Integer): String; -var - el, next: Integer; - clr: TsColorValue; - nf: TsNumberFormat; - decs: byte; - s: String; - n: Integer; -begin - Result := ''; - el := 0; - with FSections[ASection] do - while el < Length(Elements) do - begin - case Elements[el].Token of - nftColor: - begin - clr := FWorkbook.GetPaletteColor(Elements[el].IntValue); - Result := Result + - ' '; - inc(el); - end; - nftSign, nftSignBracket: - begin - Result := Result + - ' ' + Elements[el].TextValue + ''; - inc(el); - end; - nftSpace: - begin - Result := Result + - ' '; - inc(el); - end; - nftCurrSymbol: - begin - Result := Result + - ' ' + Elements[el].TextValue + - ''; - inc(el); - end; - nftIntTh: - if IsNumberAt(ASection, el, nf, decs, next) then - begin - Result := Result + Format( - ' ', - [decs, Elements[el].IntValue]); - el := next; - end; - nftIntZeroDigit: - if IsNumberAt(ASection, el, nf, decs, next) then - begin - Result := Result + Format( - ' ', - [decs, elements[el].IntValue]); - el := next; - end; - nftIntOptDigit, nftIntSpaceDigit: // To do: SpaceDigit not correct here - if IsNumberAt(ASection, el, nf, decs, next) then - begin - Result := Result + - ' '; - el := next; - end; - nftRepeat: - begin - if FSections[ASection].Elements[el].TextValue = ' ' then - s := '' else - s := FSections[ASection].Elements[el].TextValue; - Result := Result + - ' ' + s + ''; - inc(el); - end - else - inc(el); - end; // case - end; // while -end; - -function TsSpreadOpenDocNumFormatParser.BuildDateTimeXMLAsString(ASection: Integer; - out AIsTimeOnly, AIsInterval: boolean): String; -var - el: Integer; - s: String; - prevTok: TsNumFormatToken; -begin - Result := ''; - AIsTimeOnly := true; - AIsInterval := false; - with FSections[ASection] do - begin - el := 0; - while el < Length(Elements) do - begin - case Elements[el].Token of - nftYear: - begin - prevTok := Elements[el].Token; - AIsTimeOnly := false; - s := IfThen(Elements[el].IntValue > 2, 'number:style="long" ', ''); - Result := Result + - ''; - end; - - nftMonth: - begin - prevTok := Elements[el].Token; - AIsTimeOnly := false; - case Elements[el].IntValue of - 1: s := ''; - 2: s := 'number:style="long" '; - 3: s := 'number:textual="true" '; - 4: s := 'number:style="long" number:textual="true" '; - end; - Result := result + - ''; - end; - - nftDay: - begin - prevTok := Elements[el].Token; - AIsTimeOnly := false; - case Elements[el].IntValue of - 1: s := 'day '; - 2: s := 'day number:style="long" '; - 3: s := 'day-of-week '; - 4: s := 'day-of-week number:style="long" '; - end; - Result := Result + - ''; - end; - - nftHour, nftMinute, nftSecond: - begin - prevTok := Elements[el].Token; - case Elements[el].Token of - nftHour : s := 'hours '; - nftMinute: s := 'minutes '; - nftSecond: s := 'seconds '; - end; - s := s + IfThen(abs(Elements[el].IntValue) = 1, '', 'number:style="long" '); - if Elements[el].IntValue < 0 then - AIsInterval := true; - Result := Result + - ''; - end; - - nftMilliseconds: - begin - // ??? - end; - - nftDateTimeSep, nftText, nftEscaped, nftSpace: - begin - if Elements[el].TextValue = ' ' then - s := '' - else - begin - s := Elements[el].TextValue; - if (s = '/') then - begin - if prevTok in [nftYear, nftMonth, nftDay] then - s := FWorkbook.FormatSettings.DateSeparator - else - s := FWorkbook.FormatSettings.TimeSeparator; - end; - end; - Result := Result + - '' + s + ''; - end; - - nftAMPM: - Result := Result + - ''; - end; - inc(el); - end; - end; -end; -*) function TsSpreadOpenDocNumFormatParser.BuildXMLAsString(AFormatName: String): String; var i: Integer; @@ -509,7 +318,6 @@ var mask: String; timeIntervalStr: String; styleMapStr: String; - begin Result := ''; @@ -577,7 +385,7 @@ begin Result := Result + ' number:decimal-places="' + IntToStr(n) + '"'; inc(el, 2); end else - if (el = nel) or (Elements[el+1].Token <> nftDecSep) then + if (el = nel-1) or (Elements[el+1].Token <> nftDecSep) then Result := Result + ' number:decimal-places="0"'; Result := Result + ' />'; end; @@ -645,7 +453,7 @@ begin end else // Standard integer - if (el = nel) or (Elements[el+1].Token <> nftDecSep) then + if (el = nel-1) or (Elements[el+1].Token <> nftDecSep) then begin Result := Result + '' + LineEnding; - el := 1; - end; - - // Find start of number format code - while (el < Length(Elements)) and not IsNumberAt(ASection, el, nf, decs, next) do - inc(el); - - if IsNumberAt(ASection, el, nf, decs, next) then - begin - if nf = nfFixedTh then - sGrouping := 'number:grouping="true" '; - - // nfFixed, nfFixedTh - if (next = Length(Elements)) then - begin - Result := - '' + - sColor + - '' + - sStylemap + - ''; - exit; - end; - - // nfPercentage - if (nfkPercent in Kind) then - begin - Result := - '' + - sColor + - '' + - '%' + - sStyleMap + - ''; - exit; - end; - - // nfExp - if (nf = nfFixed) and IsTokenAt(nftExpChar, ASection, next) then - begin - if (next + 2 < Length(Elements)) and - IsTokenAt(nftExpSign, ASection, next+1) and - IsTokenAt(nftExpDigits, ASection, next+2) - then - expdig := Elements[next+2].IntValue - else - if (next + 1 < Length(Elements)) and - IsTokenAt(nftExpDigits, ASection, next+1) - then - expdig := Elements[next+1].IntValue - else - exit; - Result := - '' + - sColor + - '' + - sStylemap + - ''; - exit; - end; - - // nfFraction - if (nf in [nfFixed, nfFraction]) and (nfkFraction in Kind) and (decs = 0) then - begin - if IsTokenAt(nftIntOptDigit, ASection, el) then - Result := - '' + - sColor + - '' + - '' - else - Result := - '' + - sColor + - '' + - ''; - exit; - end; - - // nfCurrency - if (nfkCurrency in Kind) then - begin - Result := - '' + - BuildCurrencyXMLAsString(ASection) + - sStyleMap + - ''; - exit; - end; - end; - - // If the program gets here the format can only be date/time. - if (Kind * [nfkDate, nfkTime] <> []) then - begin - s := BuildDateTimeXMLAsString(ASection, isTimeOnly, isInterval); - if isTimeOnly then - begin - Result := Result + - '' + - s + - sStylemap + - ''; - end else - Result := Result + - '' + - s + - sStylemap + - ''; - exit; - end; - end; -end; -*) -{ TsSpreadOpenDocReader } +{******************************************************************************} +{ TsSpreadOpenDocReader } +{******************************************************************************} constructor TsSpreadOpenDocReader.Create(AWorkbook: TsWorkbook); begin diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index 3ba90184c..33fcfbdcf 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -910,6 +910,8 @@ procedure CopyCellFormat(AFromCell, AToCell: PCell); var sourceSheet, destSheet: TsWorksheet; fmt: TsCellFormat; + numFmtParams: TsNumFormatParams; + nfs: String; font: TsFont; clr: TsColorvalue; cb: TsCellBorder; @@ -923,7 +925,7 @@ begin else begin fmt := sourceSheet.ReadCellFormat(AFromCell); - destSheet.WriteCellFormat(AToCell, fmt); + //destSheet.WriteCellFormat(AToCell, fmt); if (uffBackground in fmt.UsedFormattingFields) then begin clr := sourceSheet.Workbook.GetPaletteColor(fmt.Background.BgColor); @@ -936,7 +938,9 @@ begin font := sourceSheet.ReadCellFont(AFromCell); clr := sourceSheet.Workbook.GetPaletteColor(font.Color); font.Color := destSheet.Workbook.AddColorToPalette(clr); - fmt.FontIndex := destSheet.WriteFont(AToCell, font.FontName, font.Size, font.Style, font.Color); + fmt.FontIndex := destSheet.Workbook.FindFont(font.FontName, font.Size, font.Style, font.Color); + if fmt.FontIndex = -1 then + fmt.FontIndex := destSheet.Workbook.AddFont(font.FontName, font.Size, font.Style, font.Color); end; if (uffBorder in fmt.UsedFormattingFields) then for cb in fmt.Border do @@ -944,6 +948,16 @@ begin clr := sourceSheet.Workbook.GetPaletteColor(fmt.BorderStyles[cb].Color); fmt.BorderStyles[cb].Color := destSheet.Workbook.AddColorToPalette(clr); end; + if (uffNumberformat in fmt.UsedFormattingFields) then + begin + numFmtParams := sourceSheet.Workbook.GetNumberFormat(fmt.NumberFormatIndex); + if numFmtParams <> nil then + begin + nfs := numFmtParams.NumFormatStr[nfdExcel]; + fmt.NumberFormatIndex := destSheet.Workbook.AddNumberFormat(nfs); + end; + end; + destSheet.WriteCellFormat(AToCell, fmt); end; end;