الأعمدة التي تحتوي على بيانات غير مكتوبة بشدة

إذا لم يتم كتابة جميع القيم في أعمدة ورقة العمل بشكل قوي (وهذا يعني أن القيم الموجودة في عمود قد تحتوي على أنواع بيانات مختلفة) ، فيمكننا تصدير محتوى ورقة العمل عن طريق استدعاءExportDataTableAsString طريقة الفئة Cells.ExportDataTableAsString تأخذ الطريقة نفس مجموعة المعلمات مثل تلك الخاصة بـExportDataTable طريقة لتصدير بيانات ورقة العمل كملفجدول البيانات موضوع.

 //Creating a file stream containing the Excel file to be opened

FileStream fstream = new FileStream(FOD_OpenFile.FileName, FileMode.Open);

//Instantiating a Workbook object

//Opening the Excel file through the file stream

Workbook workbook = new Workbook(fstream);

//Accessing the first worksheet in the Excel file

Worksheet worksheet = workbook.Worksheets[0];

//Exporting the contents of 2 rows and 2 columns starting from 1st cell to DataTable

DataTable dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, 2, 2, true);

//Binding the DataTable with DataGrid

dataGridView2.DataSource = dataTable;

//Closing the file stream to free all resources

fstream.Close();

فيما يلي لقطات الشاشة:

ما يجب القيام به: image_بديل_نص

ما يجب القيام به: image_بديل_نص

تنزيل نموذج التعليمات البرمجية