GridWeb den DataTable ı Dışa Aktar

Tablo Verisi Dışa Aktarma

Belirli bir DataTable’a

Çalışma sayfası verilerini belirli bir DataTable nesnesine dışa aktarmak için:

  1. Aspose.Cells.GridWeb denetimini Web Formunuza ekleyin.
  2. Belirli bir DataTable nesnesi oluşturun.
  3. Seçilen hücrelerin verilerini belirtilen DataTable nesnesine dışa aktarın.

Aşağıdaki örnek, dört sütunu olan belirli bir DataTable nesnesi oluşturur. Çalışma sayfasındaki veriler, çalışma sayfasında görünen tüm satır ve sütunlardan başlayarak, zaten oluşturulmuş bir DataTable nesnesine dışa aktarılır.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Creating a new DataTable object
DataTable dataTable = new DataTable();
// Adding specific columns to the DataTable object
dataTable.Columns.Add("Name", System.Type.GetType("System.String"));
dataTable.Columns.Add("Gender", System.Type.GetType("System.String"));
dataTable.Columns.Add("Age", System.Type.GetType("System.Int32"));
dataTable.Columns.Add("Class", System.Type.GetType("System.String"));
// Accessing the reference of the worksheet that is currently active
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];
// Getting the total number of rows and columns inside the worksheet
int totalColumns = sheet.Cells.MaxColumn + 1;
int totalRows = sheet.Cells.MaxRow + 1;
// Exporting the data of the active worksheet to a specific DataTable object
dataTable = sheet.Cells.Export(0, 0, totalRows, totalColumns, true, true);
// Display exported data table in GridView
GridView1.DataSource = dataTable;
GridView1.DataBind();

Yeni bir DataTable’a

Bazen bir DataTable nesnesi oluşturmak istemezsiniz, sadece çalışma sayfasındaki verileri yeni bir DataTable nesnesine dışa aktarmaya ihtiyacınız vardır.

Aşağıdaki örnek, Export yönteminin kullanımını farklı bir şekilde göstermeye çalışır. Etkin çalışma sayfasının referansını alır ve o çalışma sayfasının tüm verilerini yeni bir DataTable nesnesine dışa aktarır. DataTable nesnesi istediğiniz şekilde kullanılabilir. Örneğin, DataTable nesnesini verileri görüntülemek için bir GridView’e bağlamak mümkündür.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Accessing the reference of the worksheet that is currently active
GridWorksheet sheet1 = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];
// Getting the total number of rows and columns inside the worksheet
int totalColumns1 = sheet.Cells.MaxColumn + 1;
int totalRows1 = sheet.Cells.MaxRow + 1;
// Exporting the data of the active worksheet to a new DataTable object
DataTable dt = sheet.Cells.Export(0, 0, totalRows1, totalColumns1, true, true);
// Display exported data table in GridView
GridView2.DataSource = dataTable;
GridView2.DataBind();