Conversion between cell name and row/column index

Get Cell Name from Row and Column Indices

It is possible to find a cell’s name given the row and column index. This article explains how. Aspose.Cells for Python via .NET provides the CellsHelper.cell_index_to_name method which allows developers to get a cell’s name if they provide the row and column index.

The following sample code illustrates how to use CellsHelper.cell_index_to_name to access the cell’s name given a known row and column index. The code generates the following output.

import io
import aspose.cells
from aspose.cells import Workbook, Worksheet, Cells, CellsHelper
# For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
row = 3
column = 5
name = CellsHelper.cell_index_to_name(row, column)
print("Cell name: " + name)

Get Row and Column Indices from Cell Name

It is possible to find a row and column index of the cell from its name. This article explains how. Aspose.Cells for Python via .NET provides the CellsHelper.cell_name_to_index method which allows developers to get a row and column index from the cell’s name.

The following sample code illustrates how to use CellsHelper.cell_name_to_index to get the row and column index from the cell’s name. The code generates the following output.

import io
import aspose.cells
from aspose.cells import Workbook, Worksheet, Cells, CellsHelper
# For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
name = "C4";
row = []
column = []
CellsHelper.cell_name_to_index(name, row, column)
print("Row: " + str(row[0]) + " , Column: " + str(column[0]))

Create safe sheet names

Sometimes there is a need of assigning the sheet name at runtime. In this scenario, there may be sheet names which may contain some additional characters like <>+(?”. There is a need to replace any such character, which is not allowed as a sheet name with some preset character provided by user. Similarly the length may increase to more than 31 characters which needs to be truncated. Apache POI provides certain features of creating safe names, hence similar feature is provided by Aspose.Cells for Python via .NET to handle all these issues. Following sample code demonstrates this feature:

from aspose.cells import CellsHelper
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Long name will be truncated to 31 characters
name1 = CellsHelper.create_safe_sheet_name("this is first name which is created using CellsHelper.CreateSafeSheetName and truncated to 31 characters")
# Any invalid character will be replaced with _
name2 = CellsHelper.create_safe_sheet_name(" <> + (adj.Private ? \" Private\" : \")", '_')
# Display first name
print(name1)
# Display second name
print(name2)

Output:

this is first name which is cre

 <> + (adj.Private _ " Private"