Introduction
In our previous topic, we have discussed about accessing cells of a worksheet. In this topic, we will simply extend that topic to show developers that how can they access and modify the values of cells using the API of Aspose.Grid.Web.
Accessing & Modifying the Value of a Cell
String Values
Before accessing and modifying the value of a cell, we should know that how to access cells. There are few approaches to access cells of a worksheet. For more details about these approaches, please click here.
Each cell has a property named StringValue. So, once a cell is accessed, developers can access and modify the StringValue property in order to access and change the string value of a cell.
IMPORTANT: There are five types (boolean, int, double, DateTime and string) of values that can be stored in cells but StringValue property can only be used to access & modify the string values of cells. However, if a cell contains a value other than string data type then developers can also use Value property of the cell but for only accessing its value.
Example:
[C#]
//Accessing the worksheet of the Grid that is currently active
WebWorksheet sheet=GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];
//Accessing "B1" cell of the worksheet
WebCell cell=sheet.Cells["B1"];
//Accessing & modifying the string value of "B1" cell
cell.StringValue="Hello Aspose.Grid";
[VB.NET]
'Accessing the worksheet of the Grid that is currently active
Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(GridWeb1.ActiveSheetIndex)
'Accessing "B1" cell of the worksheet
Dim cell as WebCell=sheet.Cells("B1")
'Accessing & modifying the string value of "B1" cell
cell.StringValue="Hello Aspose.Grid"
All Types of Values
Using StringValue property of a cell, developers can only modify the string value of a cell. So, Aspose.Grid.Web also provides a special method, PutValue for each cell. Using this method, developers can insert or modify any type of value (that is boolean, int, double, DateTime and string) to a cell.
Example:
[C#]
//Accessing the worksheet of the Grid that is currently active
WebWorksheet sheet=GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];
//Accessing "B1" cell of the worksheet
WebCell cell=sheet.Cells["B1"];
//Putting a value in "B1" cell
cell.PutValue(DateTime.Now)
[VB.NET]
'Accessing the worksheet of the Grid that is currently active
Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(GridWeb1.ActiveSheetIndex)
'Accessing "B1" cell of the worksheet
Dim cell as WebCell=sheet.Cells("B1")
'Putting a value in "B1" cell
cell.PutValue(DateTime.Now)
NOTE: Developers may also use an overloded version of PutValue method that can take any kind of value in string format and convert that value to a proper data type automatically. To make it happen, we have to pass a true boolean value to another parameter of PutValue method as shown below in the example.
Example:
[C#]
//Accessing the worksheet of the Grid that is currently active
WebWorksheet sheet=GridWeb1.WebWorksheets[GridWeb1.ActiveSheetIndex];
//Accessing "B1" cell of the worksheet
WebCell cell=sheet.Cells["B1"];
//Putting a numeric value as string in "C4" cell that will be converted to a suitable data type automatically
cell.PutValue("19.4",true);
[VB.NET]
'Accessing the worksheet of the Grid that is currently active
Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(GridWeb1.ActiveSheetIndex)
'Accessing "B1" cell of the worksheet
Dim cell as WebCell=sheet.Cells("B1")
'Putting a numeric value as string in "C4" cell that will be converted to a suitable data type automatically
cell.PutValue("19.4",True)
Describes how to access cells in a worksheet using Aspose.Grid.Web.
8/16/2006 8:15:23 AM - -210.56.19.13