Code: Pascal [Select][+][-]program Project1;uses fpSpreadsheet, xlsxOOXML;var wBook: TsWorkbook; wSheet: TsWorksheet; r, c: Cardinal;begin wBook := TsWorkbook.Create; wSheet := wBook.AddWorksheet('Sheet 1'); // Populate work sheet for r := 0 to 10 do for c := 0 to 5 do wSheet.WriteNumber(r, c, 100*r + c); // Copy range C3:D6 to M1:N5 for r := 2 to 5 do for c := 2 to 3 do wSheet.CopyCell(r, c, r-2, c+10); wBook.WriteToFile('test.xlsx', true); wBook.Free;end.
But this is just copying the values of cells. Can we copy the values and styles within one range and copy them in another row?
Quote from: dodgex on May 13, 2025, 11:49:54 amBut this is just copying the values of cells. Can we copy the values and styles within one range and copy them in another row?No, it copies also formulas and cell formatting:Code: Pascal [Select][+][-]program Project1;uses Sysutils, fpSpreadsheet, fpsTypes, xlsxOOXML; function RandomBrightColor: DWord;var R, G, B: Byte;begin R := $FF - Random($33); G := $FF - Random($33); B := $FF - Random($33); Result := R + G shl 8 + b shl 16;end; var wBook: TsWorkbook; wSheet: TsWorksheet; cell: PCell; r, c: Cardinal;begin RandSeed := 1; wBook := TsWorkbook.Create; wSheet := wBook.AddWorksheet('Sheet 1'); // Populate work sheet for r := 0 to 10 do for c := 0 to 5 do begin if c = 3 then // Write a formula cell := wSheet.WriteFormula(r, c, '=Row(A' + IntToStr(r+1)+ ')') else // Write constant values cell := wSheet.WriteNumber(r, c, 100*r + c); // Write some random formatting wSheet.WriteBackgroundColor(cell, RandomBrightColor); if Random(2) =0 then wSheet.WriteFontStyle(cell, [fssBold, fssItalic]); end; // Copy range C3:D6 to M1:N5 for r := 2 to 5 do for c := 2 to 3 do wSheet.CopyCell(r, c, r-2, c+10); wBook.WriteToFile('test.xlsx', true); wBook.Free;end.