Spread for ASP.NET 10 Product Documentation
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, for example, in a text box, you will probably want to add the data as string data that is parsed by the FpSpread component. If you are adding several values and want to add them directly to the data model, you can add them as objects.

Formatted data usually includes information that denotes the context of the data. Unformatted data does not include additional information and might require a specific format to convey meaning. For example, formatted currency data might include currency and separator characters to indicate monetary value, as in $1,025.34. Unformatted data would not include the currency and separator characters, only the numeric value, as in 1025.34.

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

To add data to a cell using code,

To add data to a 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.

You can write HTML tags in cells using the Text property. The following code allows you to add HTML code into a cell by setting the EncodeValue property of Spread:

VB
Copy Code
FpSpread1.EncodeValue = False
FpSpread1.Cells(0, 0).Text = "<a href='http://www.componentone.com'>GrapeCity</a>" 

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 a Shortcut

Place formatted string data using the Sheet SetClip 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, 2, 2,"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, 2, 2, "Sunday" + vbTab + "Monday" + vbTab + "Tuesday" + vbCrLf + "Wednesday" + vbTab + "Thursday" + vbTab + "Friday" + vbCrLf + "Saturday" + vbTab + "Sunday" + vbTab + "Monday") 

Using Code

Add formatted string data by calling the SheetView object SetClip method.

Example

This example code adds formatted data to a range of cells.

C#
Copy Code
// Create a new SheetView object.
FarPoint.Web.Spread.SheetView newsheet=new FarPoint.Web.Spread.SheetView();
// Add data to cells A1 through C3.
newsheet.SetClip(0, 0, 2, 2, "Sunday\tMonday\tTuesday\r\nWednesday\tThursday\tFriday \r\nSaturday\tSunday\tMonday");
// Assign the SheetView object to a sheet in the component.
fpSpread1.Sheets[0] = newsheet; 
VB
Copy Code
' Create a new SheetView object.
Dim newsheet As New FarPoint.Web.Spread.SheetView()
' Add data to cells A1 through C3.
newsheet.SetClip(0, 0, 2, 2, "Sunday" + vbTab + "Monday" + vbTab + "Tuesday" + vbCrLf + "Wednesday" + vbTab + "Thursday" + vbTab + "Friday" + vbCrLf + "Saturday" + vbTab + "Sunday" + vbTab + "Monday")
' Assign the SheetView object to a sheet in the component.
FpSpread1.Sheets(0) = newsheet 

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options | Documentation Feedback