Spread Windows Forms 12.0 Product Documentation
Handling Data Using Sheet Methods
Spread Windows Forms 12.0 Product Documentation > Developer's Guide > Managing Data on a Sheet > Placing and Retrieving Data > Handling Data Using Sheet Methods

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

GetText

SetText

  Range of cells

GetClip

SetClip

As a string without formatting (for example "1234.45") Individual cell

GetValue

SetValue

  Range of cells

GetClipValue

SetClipValue

As a data object with formatting Range of cells

GetArray

SetArray

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 and Format 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.

  1. At design time, in the Properties window, select the Spread component.
  2. Select the Sheets property.
  3. Click the button to display the SheetView Collection Editor.
  4. Click the sheet for which you want to add data.
  5. Select the Cells property and then click the button to display the Cell, Column, and Row Editor.
  6. Select the cell or range of cells to which you want to add data.
  7. In the property list, set the Text property.
  8. Click OK to close the Cell, Column, and Row Editor.
  9. Click OK to close the SheetView Collection Editor.

Using a Shortcut

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

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