Cell 値へのアクセスと変更
Contents
[
Hide
]
アクセス ワークシート Cellsセルへのアクセスについて説明しました。このトピックでは、その説明を拡張して、Aspose.Cells.GridWeb API を使用してセル値にアクセスして変更する方法を示します。
Cell の値へのアクセスと変更
文字列値
セルの値にアクセスして変更する前に、セルへのアクセス方法を知っておく必要があります。セルにアクセスするためのさまざまなアプローチの詳細については、次を参照してください。アクセス ワークシート Cells.
各セルには、StringValue という名前のプロパティがあります。セルにアクセスすると、開発者は StringValue プロパティを使用してセルの文字列値にアクセスできます。セル値を変更するために、セルの文字列値を更新するために使用できる特別なメソッド PutValue が提供されています。
This file contains 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 | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Accessing "B1" cell of the worksheet | |
GridCell cell = sheet.Cells["B1"]; | |
// Accessing the string value of "B1" cell | |
Label1.Text = cell.StringValue; | |
// Modifying the string value of "B1" cell | |
cell.PutValue("Hello Aspose.Grid"); |
すべてのタイプの値
セルのオブジェクトの PutValue メソッドには、セル内の任意のタイプの値 (Boolean、int、double、DateTime、および string) を変更するために使用できる 8 つのオーバーロードがあります。
This file contains 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 | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Accessing "B3" cell of the worksheet | |
GridCell cell = sheet.Cells["B3"]; | |
// Putting a value in "B3" cell | |
cell.PutValue(30); |
文字列形式の任意の種類の値を取得し、適切なデータ型に自動的に変換できる、PutValue メソッドのオーバーロードされたバージョンもあります。これを実現するには、以下の例に示すように、ブール値 true を PutValue メソッドの別のパラメーターに渡します。
This file contains 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 | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Accessing "B5" cell of the worksheet | |
GridCell cell = sheet.Cells["B5"]; | |
// Putting a numeric value as string in "B5" cell that will be converted to a suitable data type automatically | |
cell.PutValue("19.4", true); |