Importar DataView a GridWeb
Importar datos desde DataView
Importar datos desde un objeto DataView usando el método ImportDataView de la colección GridWorsheetCollection en el control GridWeb. Pasa el objeto DataView del cual deseas importar datos al método ImportDataView. Es posible especificar el encabezado de columna y los estilos de datos durante la importación.
Salida: Datos importados desde un DataView a una nueva hoja de cálculo
Los anchos de las columnas se ajustan para mostrar todos los datos que contienen. Cuando se importan los datos de un DataView, los anchos de columna no se ajustan automáticamente. Los usuarios necesitan ajustarlos por ellos mismos. Para ajustar los anchos de columna programáticamente, consulta Redimensionar Filas y Columnas.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Connect database | |
System.Data.OleDb.OleDbConnection oleDbConnection1 = new OleDbConnection(); | |
System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1 = new OleDbDataAdapter(); | |
System.Data.OleDb.OleDbCommand oleDbSelectCommand1 = new OleDbCommand(); | |
string path = (this.Master as Site).GetDataDir(); | |
oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\Worksheets\\Database\\Northwind.mdb"; | |
oleDbSelectCommand1.Connection = oleDbConnection1; | |
oleDbDataAdapter1.SelectCommand = oleDbSelectCommand1; | |
DataTable dataTable1 = new DataTable(); | |
dataTable1.Reset(); | |
// Queries database. | |
try | |
{ | |
oleDbSelectCommand1.CommandText = "SELECT CategoryID, CategoryName, Description FROM Categories"; | |
oleDbDataAdapter1.Fill(dataTable1); | |
} | |
catch | |
{ | |
} | |
finally | |
{ | |
oleDbConnection1.Close(); | |
} | |
// Imports data from dataview object. | |
dataTable1.TableName = "Categories"; | |
GridWeb1.WorkSheets.Clear(); | |
GridWeb1.WorkSheets.ImportDataView(dataTable1.DefaultView, null, null); | |
// Imports data from dataview object with sheet name and position specified. | |
GridWeb1.WorkSheets.ImportDataView(dataTable1.DefaultView, null, null, "SpecifiedName&Position", 2, 1); |