Skip to main content Skip to footer

Spread Windows Forms and Loading Data

An important part of a Spreadsheet is adding data. Spread for Windows Forms has many ways to add data. You can load files, bind to data sources, or use methods and properties to add data to cells. The following table lists the different ways you can load files:

Method

File Type

Description

Open

Spread XML files

Spread can open data or data and formatting from a Spread-compatible XML file or a stream.

OpenExcel

Excel-formatted files

You can open an existing Excel-formatted file (BIFF8 format or xlsx) in Spread.

OpenSpreadFile

Spread COM ss7 or ss8 files

You can open an existing file from the COM version of Spread (Spread COM 7.0 or later).

LoadTextFile

Text or comma-delimited files

You can open existing text files that are delimited, either files saved from Spread or delimited text files from other sources.

You can use the DataSource property to bind Spread. You can bind the Spread component to a data set, such as data in a database, or to anything that the .NET framework allows, such as an IList object. You can bind to a cell range with the MapperInfo class, the SpreadDataBindingAdapter class, and the FillSpreadDataByDataSource method. This example binds the control to a data set. SpreadWinBinding Data Set C#

DataSet ds = new DataSet();  
DataTable emp = new DataTable("Product");  
DataTable div = new DataTable("Total Cost");  
emp.Columns.Add("Name");  
emp.Columns.Add("Category");  
emp.Rows.Add(new Object[] { "Apple", "Fruit" });  
emp.Rows.Add(new Object[] { "Orange", "Fruit" });  
emp.Rows.Add(new Object[] { "Plum", "Fruit" });  
emp.Rows.Add(new Object[] { "Kiwi", "Fruit" });  
emp.Rows.Add(new Object[] { "Strawberry", "Fruit" });  
emp.Rows.Add(new Object[] { "Broccoli", "Vegetable" });  
emp.Rows.Add(new Object[] { "Celery", "Vegetable" });  
emp.Rows.Add(new Object[] { "Artichoke", "Vegetable" });  
emp.Rows.Add(new Object[] { "Okra", "Vegetable" });  
div.Columns.Add("Price");  
div.Columns.Add("Quantity");  
div.Rows.Add(new Object[] { "1.99 per pound", "100" });  
div.Rows.Add(new Object[] { "2.00 per pound", "50" });  
div.Rows.Add(new Object[] { "1.75 per pound", "150" });  
div.Rows.Add(new Object[] { "2.50 per pound", "80" });  
div.Rows.Add(new Object[] { "1.75 per pound", "150" });  
div.Rows.Add(new Object[] { "2.50 per pound", "100" });  
div.Rows.Add(new Object[] { "1.00 per pound", "250" });  
div.Rows.Add(new Object[] { "4.75 per pound", "50" });  
div.Rows.Add(new Object[] { "1.00 per pound", "150" });  
ds.Tables.AddRange(new DataTable[] { emp, div });  
fpSpread1.DataSource = ds;  
fpSpread1.DataMember = "Product";  

VB

Dim ds As New DataSet()  
Dim emp As New DataTable("Product")  
Dim div As New DataTable("Total Cost")  
emp.Columns.Add("Name")  
emp.Columns.Add("Category")  
emp.Rows.Add(New Object() {"Apple", "Fruit"})  
emp.Rows.Add(New Object() {"Orange", "Fruit"})  
emp.Rows.Add(New Object() {"Plum", "Fruit"})  
emp.Rows.Add(New Object() {"Kiwi", "Fruit"})  
emp.Rows.Add(New Object() {"Strawberry", "Fruit"})  
emp.Rows.Add(New Object() {"Broccoli", "Vegetable"})  
emp.Rows.Add(New Object() {"Celery", "Vegetable"})  
emp.Rows.Add(New Object() {"Artichoke", "Vegetable"})  
emp.Rows.Add(New Object() {"Okra", "Vegetable"})  
div.Columns.Add("Price")  
div.Columns.Add("Quantity")  
div.Rows.Add(New Object() {"1.99 per pound", "100"})  
div.Rows.Add(New Object() {"2.00 per pound", "50"})  
div.Rows.Add(New Object() {"1.75 per pound", "150"})  
div.Rows.Add(New Object() {"2.50 per pound", "80"})  
div.Rows.Add(New Object() {"1.75 per pound", "150"})  
div.Rows.Add(New Object() {"2.50 per pound", "100"})  
div.Rows.Add(New Object() {"1.00 per pound", "250"})  
div.Rows.Add(New Object() {"4.75 per pound", "50"})  
div.Rows.Add(New Object() {"1.00 per pound", "150"})  
ds.Tables.AddRange(New DataTable() {emp, div})  
FpSpread1.DataSource = ds  
FpSpread1.DataMember = "Product"  

You can place data in cells as formatted or unformatted strings or as data objects. The following table summarizes the ways you can add data using methods at the sheet level:

Data

Description

Method

As a string with formatting (for example "$1,234.56")

Individual cell

SetText GetText

Range of cells

SetClip GetClip

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

Individual cell

SetValue GetValue

Range of cells

SetClipValue GetClipValue

As a data object with formatting

Range of cells

SetArray GetArray

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. This example uses the SetArray method. C#

fpSpread1.ActiveSheet.SetArray(1, 0, new String[,] { { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" } });

VB

FpSpread1.ActiveSheet.SetArray(1, 0, New String(,) "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}})

This example uses the SetClip method. C#

fpSpread1.ActiveSheet.SetClip(0, 0, 3, 4, "January\\tFebruary\\tMarch\\tApril\\r\\nMay\\tJune\\tJuly\\tAugust\\r\\nSeptember\\tOctober\\tNovember\\tDecember");

VB

FpSpread1.ActiveSheet.SetClip(0, 0, 3, 4, "January" + Chr(9) + "February" + Chr(9) + "March" + Chr(9) + "April" + vbCrLf + "May" + Chr(9) +  
 "June" + Chr(9) + "July" + Chr(9) + "August" + vbCrLf + "September" + Chr(9) + "October" + Chr(9) + "November" + Chr(9) + December")  

The following table lists the ways you can get or set data in cells using properties of the cell:

Data

Cell Property

As a string with formatting (for example "$1,234.56")

Text

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

Value

MESCIUS inc.

comments powered by Disqus