You can place data in cells as formatted or unformatted strings or as data objects. The best way to place data in cells depends on whether you want to add string data or data objects, and if you want to add data to an individual cell or to a range of cells.
If you are working with data provided by a user in a text box, for example, you probably want to add the data as string data that is parsed by the Spread component. If you are adding several values and want to add them directly to the data model, you can add them as objects.
The following table summarizes the ways you can add data using methods at the sheet level.
Data Description | How Many Cells | Method |
---|---|---|
As a string with formatting (for example "$1,234.56") | Individual cell | |
Range of cells | ||
As a string without formatting (for example "1234.45") | Individual cell | |
Range of cells | ||
As a data object with formatting | Range of cells |
When you work with formatted data, the data is parsed by the cell type formatted for that cell and placed in the data model. When you work with unformatted data, the data goes directly into the data model. If you add data to the sheet that is placed directly into the data model, you might want to parse the data because the component does not do so. To understand the effect that the cell type has on this data, refer to the summary in Understanding How Cell Types Display Data.
For detailed information about how to provide the data for each cell type, see the member topics in the FarPoint.Win.Spread.CellType namespace.
To add a large amount of information to the component, consider creating and opening existing files, such as text files or Excel-formatted files, as explained in Opening Existing Files.
You can also return data by saving the data or the data and formatting to a text file, Excel-formatted file, or Spread XML file. For instructions for saving data to these file types, see Saving Data to a File.
Using the Properties Window
To add data to a cell, follow these instructions. You cannot add data to a range of cells unless you want to add the same data to all the cells in the range you select.
- At design time, in the Properties window, select the Spread component.
- Select the Sheets property.
- Click the button to display the SheetView Collection Editor.
- Click the sheet for which you want to add data.
- Select the Cells property and then click the button to display the Cell, Column, and Row Editor.
- Select the cell or range of cells to which you want to add data.
- In the property list, set the Text property.
- Click OK to close the Cell, Column, and Row Editor.
- Click OK to close the SheetView Collection Editor.
Using a Shortcut
- To get or set data to a cell using code,
- To get or set data to a range of cells,
- Place formatted string data using the Sheets SetClip method or retrieve the data using the GetClip method.
- Place unformatted string data using the Sheets SetClipValue method or retrieve data using the GetClipValue method.
- Add data as objects directly into the data model using the Sheets SetArray method or retrieve the data using the GetArray method.
Example
This example code adds formatted data to a range of cells.
C# | Copy Code |
---|---|
// Add data to cells A1 through C3. fpSpread1.Sheets[0].SetClip(0, 0, 3, 3,"Sunday\tMonday\tTuesday\r\nWednesday\tThursday\tFriday\r\nSaturday\tSunday\tMonday"); |
VB | Copy Code |
---|---|
' Add data to cells A1 through C3. FpSpread1.Sheets(0).SetClip(0, 0, 3, 3, "Sunday" + vbTab + "Monday" + vbTab + "Tuesday" + vbCrLf + "Wednesday" + vbTab + "Thursday" + vbTab + "Friday" + vbCrLf + "Saturday" + vbTab + "Sunday" + vbTab + "Monday") |
Using Code
- To add data to a cell using code,
- Add formatted string data by calling the SheetView object SetText method or by calling the Cell object Text property.
- Add data as objects directly into the data model by calling the SheetView object SetValue method or by calling the Cell object Value property.
- To add data to a range of cells,
- Add formatted string data by calling the SheetView object SetClip method.
- Add unformatted string data by calling the SheetView object SetClipValue method.
- Add data as objects directly into the data model by calling the SheetView object SetArray method.
Example
This example code adds formatted data to a range of cells.
C# | Copy Code |
---|---|
// Create a new SheetView object. FarPoint.Win.Spread.SheetView newsheet=new FarPoint.Win.Spread.SheetView(); // Add data to cells A1 through C3. newsheet.SetClip(0, 0, 3, 3, "Sunday\tMonday\tTuesday\r\nWednesday\tThursday\tFriday \r\nSaturday\tSunday\tMonday"); // Assign the SheetView object to be the first sheet. fpSpread1.Sheets[0] = newsheet; |
VB | Copy Code |
---|---|
' Create a new SheetView object. Dim newsheet As New FarPoint.Win.Spread.SheetView() ' Add data to cells A1 through C3. newsheet.SetClip(0, 0, 3, 3, "Sunday" + vbTab + "Monday" + vbTab + "Tuesday" + vbCrLf + "Wednesday" + vbTab + "Thursday" + vbTab + "Friday" + vbCrLf + "Saturday" + vbTab + "Sunday" + vbTab + "Monday") ' Assign the SheetView object to be the first sheet. FpSpread1.Sheets(0) = newsheet |