Recent

Author Topic: How to get column/row names? [SOLVED]  (Read 4914 times)

Vittorio

  • New Member
  • *
  • Posts: 32
How to get column/row names? [SOLVED]
« on: September 06, 2017, 09:42:15 am »
Is there a simple way to get column names (such as "A", "B") and row names (such as "1", "2") for WorksheetGrid cell?
Thanks.
« Last Edit: September 06, 2017, 11:42:24 am by Vittorio »

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: How to get column/row names?
« Reply #1 on: September 06, 2017, 11:04:34 am »
Code: Pascal  [Select][+][-]
  1. rowstr := IntToStr(ARowIndex+1);
  2. colStr := GetColString(AColIndex: Integer);
  3. cellStr := GetCellString(ARowIndex, AColIndex);

But note that the row and column indexes refer to the worksheet, not the grid. The grid indexes will be offset by 1 if its headers are shown, i.e. if grid.ShowHeaders is true. Use the grid functions GetWorksheetCol(AGridCol) and GetWorksheetRow(AGridRow) for conversion independently of headers shown or not.

For example to get the Excel notation of the currently selected grid cell:
Code: Pascal  [Select][+][-]
  1. var
  2.   sheetCol, sheetRow: Integer;
  3. begin
  4.   sheetCol := grid.GetWorksheetCol(grid.Col);
  5.   sheetRow := grid.GetWorksheetRow(grid.Row);
  6.   ShowMessage('The currently selected cell is ' + GetCellString(sheetRow, sheetCol));
  7. end;


Vittorio

  • New Member
  • *
  • Posts: 32
Re: How to get column/row names?
« Reply #2 on: September 06, 2017, 11:41:56 am »
Thanks a lot!

Relativity

  • Full Member
  • ***
  • Posts: 103
Re: How to get column/row names? [SOLVED]
« Reply #3 on: January 18, 2018, 10:49:58 am »
Is it possible to get rows' and columns' names from TsWorksheet instead of from TsWorksheetGrid ?
"How'm I gonna get through?"
  -- Pet Shop Boys

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: How to get column/row names? [SOLVED]
« Reply #4 on: January 18, 2018, 12:30:37 pm »
  • The row name is just the same as IntToStr(ARowIndex+1).
  • The column name can be obtained from GetColString(AColumnIndex) (in fpsutils) ( colindex 0 --> 'A').
  • The cell address name can be obtained from GetCellString(ARowIndex, AColIndex), in fpsutils, too (rowindex 0, colindex 0 --> 'A1'.
  • The name of a cell range starting at top-left corner ARow1,ACol1 and ending at bottom-right corner ARow2,ACol2 can be obtained from GetCellRangeString(ARow1, ACol1, ARow2, ACol2) (--> ARow1=0, ACol1=0, ARow2=1, ACol2 = 1 --> 'A1B2') (again in fpsutils).

Relativity

  • Full Member
  • ***
  • Posts: 103
Re: How to get column/row names? [SOLVED]
« Reply #5 on: January 18, 2018, 02:02:18 pm »
I apologize for my ill-posed question.
I had not understood at all that the GetColString function etc.. are functions from the fpsutils unit.
I didn't understand where these utility functions came from and I thought they were maybe TsWorksheetGrid's methods. Therefore I asked if something similar was available also in TsWorksheet.

I apologize and thank you for your patience.

"How'm I gonna get through?"
  -- Pet Shop Boys

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: How to get column/row names? [SOLVED]
« Reply #6 on: January 18, 2018, 02:56:02 pm »
No need to apologize.

 

TinyPortal © 2005-2018