单元格名称和行/列索引之间的转换

如何从行和列索引获取单元格名称

可以通过给定行和列索引来查找单元格的名称。 本文解释了如何操作。

Aspose.Cells 提供了 CellsHelper.cellIndexToName 方法,允许开发人员在提供行和列索引的情况下获取单元格的名称。

以下示例代码说明如何使用 CellsHelper.cellIndexToName 访问已知行和列索引处的单元格名称。该代码生成以下输出。

Cell Name at [0, 0]: A1

Cell Name at [4, 0]: A5

Cell Name at [0, 4]: E1

Cell Name at [2, 2]: C3
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String cellname = CellsHelper.cellIndexToName(0, 0);
System.out.println("Cell Name at [0, 0]: " + cellname);
cellname = CellsHelper.cellIndexToName(4, 0);
System.out.println("Cell Name at [4, 0]: " + cellname);
cellname = CellsHelper.cellIndexToName(0, 4);
System.out.println("Cell Name at [0, 4]: " + cellname);
cellname = CellsHelper.cellIndexToName(2, 2);
System.out.println("Cell Name at [2, 2]: " + cellname);

如何从单元格名称获取行和列索引

可以从单元格名称中找到单元格的行和列索引。 本文解释了如何操作。

Aspose.Cells提供了CellsHelper.cellNameToIndex方法,允许开发人员从单元格名称获取行和列索引。

以下示例代码说明如何使用CellsHelper.cellNameToIndex获取单元格名称的行和列索引。代码生成以下输出。

Row Index of Cell C6: 5

Column Index of Cell C6: 2
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
int[] cellIndices = CellsHelper.cellNameToIndex("C6");
System.out.println("Row Index of Cell C6: " + cellIndices[0]);
System.out.println("Column Index of Cell C6: " + cellIndices[1]);

如何创建安全的工作表名称

有时需要在运行时分配工作表名称。在这种情况下,可能存在包含一些额外字符(如<>+(?的工作表名称。需要替换任何不允许作为工作表名称的字符,使用用户提供的预设字符。同样,长度可能会增加到超过31个字符,需要截断。Apache POI提供了创建安全名称的某些功能,因此Aspose.Cells提供了类似的功能以处理所有这些问题。以下示例代码演示了这一特性:

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

控制台输出

这是第一个名字,它是特别私人的

` `<> + (adj.Private _ " Private"