访问和修改 a Cell 的值
Contents
[
Hide
]
在我们之前的主题中,我们讨论了如何访问工作表的单元格。在本主题中,我们将简单地扩展该主题以向开发人员展示他们如何使用 Aspose.Cells.GridDesktop 的 API 访问和修改单元格的值。
使用 Aspose.Cells.GridDesktop 访问和修改 Cell 值
在访问和修改单元格的值之前,我们应该知道如何访问单元格。可以通过三种方法访问工作表的单元格。有关这三种方法的更多详细信息,请在工作表中访问 Cells。
每个单元格都有一个名为 Value 的属性。因此,一旦访问了单元格,开发人员就可以访问和修改 Value 属性的内容,以便访问和更改单元格的值。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 属性修改其值是设置单个或几个单元格值的好方法。如果您需要设置许多单元格的值,那么这种方法的性能不会很好。因此,要设置多个单元格的值,您应该使用设置单元格值用于提高应用程序性能的单元方法。上述代码片段的修改版本使用设置单元格值方法如下所示。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |