Recent

Author Topic: from spreadsheet get range selected  (Read 956 times)

eldonfsr

  • Sr. Member
  • ****
  • Posts: 450
from spreadsheet get range selected
« on: December 21, 2023, 04:24:10 pm »
Hello how i can get from fspreadsheet range of rows selected , i tried some but i don't get it..

Code: Pascal  [Select][+][-]
  1. procedure TFormmain.MIRangeLabsClick(Sender: TObject);
  2. var
  3.   ws: TsWorksheet;
  4.   allSelRange: TsCellRangeArray;
  5.   SeleRange: TsCellRange;
  6.   activeCellRow,activeCellCol: Cardinal;
  7.  egin
  8.    ws := sWorkbookSource1.Workbook.ActiveWorksheet;
  9.    activeCellRow := ws.ActiveCellRow;
  10.    activeCellCol := ws.ActiveCellCol;
  11. //   SeleRange :=  ws.GetSelection;
  12.   SeleRange := ws.GetCurrentRange(ws, activeCellRow, activeCellCol);
  13.  
what i need is a list of rows selected..

thanks any help great..
« Last Edit: December 23, 2023, 07:21:54 pm by eldonfsr »

wp

  • Hero Member
  • *****
  • Posts: 12013
Re: of spreadsheet get range selected
« Reply #1 on: December 21, 2023, 05:20:51 pm »
I am a bit confused: Your code is mainly about a worksheet (ws), but there is also a WorkbookSource which indicates that you might be working with a WorksheetGrid. My point is: How and where do you select the rows? In the worksheet by calling SetSelection? Or in the WorksheetGrid by dragging the mouse? Do you really select entire rows or just blocks of cells? In Excel you would select a row by clicking on the row header, but IIRC, the WorksheetGrid does not provide this method. And related question: Is your selection a contiguous block (1 rectangle) or does it consist of several blocks?

eldonfsr

  • Sr. Member
  • ****
  • Posts: 450
Re: of spreadsheet get range selected
« Reply #2 on: December 21, 2023, 09:15:01 pm »
Ok i understand well for my don't problem i need to do selection in wsgrid or ws just for me i get range of selections of rows ..

you can see what i doing..
 
just on procedure TFormmain.MIRangeLabsClick(Sender: TObject);

   for Rp:= allSelRange[0].Row1 to  allSelrange[0].Row2 do begin
      PrintQrLabel(RP, RP); here calling to print label is all what i need send the information of row
   end;
« Last Edit: December 21, 2023, 09:50:08 pm by eldonfsr »

wp

  • Hero Member
  • *****
  • Posts: 12013
Re: of spreadsheet get range selected
« Reply #3 on: December 21, 2023, 10:32:58 pm »
I still don't fully understand what this is about, but from your experiments in TFormMain.MIRangeLabsClick I guess that you want to determine the row indices of the cells that you had selected in the grid earlier.

Here is a modified version of this procedure:
Code: Pascal  [Select][+][-]
  1. procedure TFormmain.MIRangeLabsClick(Sender: TObject);
  2. var
  3.   ws: TsWorksheet;
  4.   allSelRange: TsCellRangeArray;
  5.   log: TStringList;
  6.   Rp, j:Integer;
  7. begin
  8.    log:= TStringList.Create;
  9.    ws := sWorkbookSource1.Workbook.ActiveWorksheet;
  10.    allSelRange := ws.GetSelection;
  11.    for j := 0 to High(allSelRange) do
  12.      for Rp:= allSelRange[j].Row1 to  allSelRange[j].Row2 do begin
  13.         PrintQrLabel(RP, RP);
  14.         log.Add(inttostr(Rp));
  15.         log.savetofile('log.txt');
  16.      end;
  17.    log.Free;
  18. end;

Note that it also considers the case that the user has selected multiple blocks (overlapping blocks are not handled and thus might be contained in the result set multiple times).

eldonfsr

  • Sr. Member
  • ****
  • Posts: 450
Re: of spreadsheet get range selected
« Reply #4 on: December 23, 2023, 07:20:42 pm »
Yes i using the worksheetgrid to show to user information and from let him  select area of row nd columns also i don't have problem is select a rows only for send to the printer information only need row to extract the values from sheet , why i doing that they have a sheer with hole information for inventory but some of them need to print qr barcode...

thanks for your help....
 

 

TinyPortal © 2005-2018