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 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.
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.
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") |
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 |