访问和修改单元格的值

使用Aspose.Cells.GridDesktop访问和修改单元格的值

在访问和修改单元格的值之前,我们应该知道如何访问单元格。有三种访问工作表单元格的方法。有关这三种方法的详细信息,请参阅在工作表中访问单元格

每个单元格都有一个名为Value的属性。因此,一旦访问了单元格,开发人员就可以访问和修改Value属性的内容,从而访问和更改单元格的值。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Accessing the worksheet of the Grid that is currently active
Worksheet sheet = gridDesktop1.GetActiveWorksheet();
// Accessing the cell using its name
GridCell cell = sheet.Cells["A1"];
// Accessing & modifying the value of "A1" cell
cell.Value = DateTime.Now;

重要提示: 使用单元格的Value属性修改其值是设置单个或少量单元格的值的良好方法。如果需要设置许多单元格的值,则此方法的性能将不佳。因此,为了设置许多单元格的值,应使用单元格的SetCellValue方法来提高应用程序的性能。下面显示了使用SetCellValue方法的上述代码片段的修改版本。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Accessing the worksheet of the Grid that is currently active
Worksheet sheet = gridDesktop1.GetActiveWorksheet();
// Accessing the cell using its name
GridCell cell = sheet.Cells["A1"];
// Setting the value of "A1" cell
cell.SetCellValue(DateTime.Now);