Introduction
With the release of Microsoft .NET Framework, we are introduced to a new way of storing data with the help of DataSet, DataTable and DataView objects that store data in offline mode. These objects are very handy to act as a repository of data. Using Aspose.Grid.Web, it's possible for developers to import their data (stored in either DataTable or DataView objects) into worksheets. Aspose.Grid.Web only supports importing data from a DataView object but a DataTable object can also be used indirectly. Let's discuss this feature in detail.
Importing Data from DataView
Developers can import data from DataView object by using ImportDataView method of WebWorksheets collection of GridWeb control. We can pass DataView object (whose data is to be imported) to ImportDataView method. While importing data, developers can also specify the styles of column headers and data.
NOTE: When data is imported from DataView object, a new worksheet is created to hold the imported data. Moreover, the worksheet is named according to the name of the DataTable.
Example:
[C#]
//Creating DataTable object to hold Products information
DataTable dt=new DataTable("Products");
//Adding appropriate columns to Products DataTable
dt.Columns.Add("Product_ID",typeof(System.Int32));
dt.Columns.Add("Product_Name",typeof(System.String));
dt.Columns.Add("Product_Price",typeof(System.Int32));
dt.Columns.Add("Currency_Unit",typeof(System.String));
//Filling Products DataTable with some data
dt.Rows.Add(new string[]{"1","Large Bed Sheet","100","Euro"});
dt.Rows.Add(new string[]{"2","Wheel Chair","250","Euro"});
dt.Rows.Add(new string[]{"3","Medium Size Table","500","Euro"});
dt.Rows.Add(new string[]{"4","Fancy Clock","95","Euro"});
dt.Rows.Add(new string[]{"5","Small Carpet","800","Euro"});
//Getting the reference of default DataView of Products DataTable
DataView dv=dt.DefaultView;
//Importing data from DataView
GridWeb1.WebWorksheets.ImportDataView(dv,null,null);
[VB.NET]
'Creating DataTable object to hold Products information
Dim dt As DataTable = New DataTable("Products")
'Adding appropriate columns to Products DataTable
dt.Columns.Add("Product_ID", Type.GetType("System.Int32"))
dt.Columns.Add("Product_Name", Type.GetType("System.String"))
dt.Columns.Add("Product_Price", Type.GetType("System.Int32"))
dt.Columns.Add("Currency_Unit", Type.GetType("System.String"))
'Filling Products DataTable with some data
dt.Rows.Add(New String() {"1", "Large Bed Sheet", "100", "Euro"})
dt.Rows.Add(New String() {"2", "Wheel Chair", "250", "Euro"})
dt.Rows.Add(New String() {"3", "Medium Size Table", "500", "Euro"})
dt.Rows.Add(New String() {"4", "Fancy Clock", "95", "Euro"})
dt.Rows.Add(New String() {"5", "Small Carpet", "800", "Euro"})
'Getting the reference of default DataView of Products DataTable
Dim dv As DataView = dt.DefaultView
'Importing data from DataView
GridWeb1.WebWorksheets.ImportDataView(dv, Nothing, Nothing)
The output of above code snippet is displayed in the figure shown below:
|
Figure: Data imported from DataView into a new worksheet
|
In the above figure, you can see that the widths of all columns are adjusted to show all data with complete visibility. When data is imported from DataView, these column widths are not adjusted automatically. Users need to adjust them by themselves. If you want to adjust the column widths programmatically by yourself then please refer to Setting Row Height & Column Width.
NOTE: An overloaded version of ImportDataView method also allows developers to specify a desired sheet name (of the sheet that holds imported data) and a specific number of rows and columns to import from DataView object.
Describes how to set row height and column width of Aspose.Grid.Web.
8/16/2006 8:06:05 AM - -210.56.19.13