تصدير البيانات من الشبكة

تصدير محتويات الشبكة

التصدير إلى DataTable محدد

لتصدير محتويات الشبكة إلى كائن DataTable محدد ، يرجى اتباع الخطوات التالية: إضافة Aspose.Cells.GridDesktop control إلى حسابكاستمارة.

  • قم بإنشاء كائن DataTable محدد وفقًا لاحتياجاتك.
  • تصدير بيانات ملفورقة عمل إلى كائن DataTable المحدد الخاص بك.

في المثال الموضح أدناه ، قمنا بإنشاء كائن DataTable محدد بداخله أربعة أعمدة. أخيرًا ، قمنا بتصدير بيانات ورقة العمل (بدءًا من الخلية الأولى المكونة من 69 صفًا و 4 أعمدة) إلى كائن DataTable أنشأناه بالفعل.

مثال:

// 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("ProductName", System.Type.GetType("System.String"));
dataTable.Columns.Add("CategoryName", System.Type.GetType("System.String"));
dataTable.Columns.Add("QuantityPerUnit", System.Type.GetType("System.String"));
dataTable.Columns.Add("UnitsInStock", System.Type.GetType("System.Int32"));
// Exporting the data of the first worksheet of the Grid to the specific DataTable object
dataTable = gridDesktop1.Worksheets[0].ExportDataTable(dataTable, 0, 0, 69, 4, true);

التصدير إلى جدول بيانات جديد

في بعض الأحيان ، قد لا يهتم المطورون بإنشاء كائن DataTable الخاص بهم وقد يحتاجون ببساطة إلى تصدير بيانات ورقة العمل إلى كائن DataTable جديد. ستكون أسرع طريقة للمطورين فقط لتصدير بيانات ورقة العمل.

في المثال الموضح أدناه ، جربنا طريقة مختلفة لشرح استخدام طريقة ExportDataTable. لقد أخذنا مرجع ورقة العمل النشطة حاليًا ثم قمنا بتصدير البيانات الكاملة لورقة العمل النشطة إلى كائن DataTable جديد. الآن ، يمكن استخدام كائن DataTable هذا بأي طريقة يريدها المطور. على سبيل المثال فقط ، يجوز للمطور ربط كائن DataTable هذا بـ DataGrid لعرض البيانات.

مثال:

// 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
Worksheet sheet = gridDesktop1.GetActiveWorksheet();
//Getting the total number of rows and columns inside the worksheet
int totalRows = sheet.RowsCount;
int totalCols = sheet.ColumnsCount;
// Exporting the data of the active worksheet to a new DataTable object
DataTable table = sheet.ExportDataTable(0, 0, totalRows, totalCols, false, true);