Recent

Author Topic: fpspreadsheet, How to write text on a merge cell?  (Read 431 times)

incendio

  • Sr. Member
  • ****
  • Posts: 291
fpspreadsheet, How to write text on a merge cell?
« on: September 02, 2024, 11:40:44 am »
Hi guys

I have this codes
Code: Pascal  [Select][+][-]
  1.  
  2. function TMainFrm.RptRcvDOC(RptNm : string) : string;
  3. var
  4.   WB        : TsWorkbook;
  5.   WS        : TsWorksheet;
  6.   FNm       : string;
  7.   FrmN      : string;
  8.  
  9. begin
  10.   try
  11.     WB := TsWorkbook.Create;
  12.     WB.ReadFromFile('XLFiles.xlsx');
  13.     WS := WB. ActiveWorksheet;
  14.     FrmN := GetFrmN(RptNm);
  15.     FNm := 'XL' + FrmN + '.xlsx';
  16.  
  17.     WS.WriteText(3,5,FrmN);
  18.     WS.WriteText(6,24,'Test');
  19.  
  20.     WB.WriteToFile(FNm,true);
  21.     OpenDocument(FNm);
  22.     Result := 'OK';
  23.  
  24.   except on E: Exception do
  25.   begin
  26.     Result := E.Message;
  27.   end;
  28.   WB.Free;
  29.   Result := 'OK';
  30. end;
  31.  

This code : WS.WriteText(6,24,'Test'), write to a merge cell, attached is a sample xl file.

It didn't work. If it was not a merge cell, worked OK.

Any hints, how to solved this problem?

PS : Lazarus 2.2.2, fpspreadsheet 1.14.0.0, on Windows 10.


wp

  • Hero Member
  • *****
  • Posts: 12526
Re: fpspreadsheet, How to write text on a merge cell?
« Reply #1 on: September 02, 2024, 12:37:16 pm »
Text as well as formatting of merged cells is taken from the top/left cell of the merged block. The merged block in your test file that you probably mean, however, does not begin at column 24, but at column 23 (row and column indices in FPSpreadsheet are 0-based, in Excel 1-based)

incendio

  • Sr. Member
  • ****
  • Posts: 291
Re: fpspreadsheet, How to write text on a merge cell?
« Reply #2 on: September 02, 2024, 02:01:33 pm »
You were right.

On a row before a merge cell , text was written at column 24. So, on a merge cell, I repeated write to column 24 instead of column 23, really missed that.

Thanks for your help 👍

 

TinyPortal © 2005-2018