فتح ملف إكسل
مقدمة
لفتح ملف Excel باستخدام Aspose.Cells.GridDesktop ، يجب عليك إنشاء تطبيق سطح مكتب باستخدام GridDesktop Control فيه. إذا كنت لا تعرف كيفية إضافة Aspose.Cells.GridDesktop control إلى نموذج windows الخاص بك ، فعليك الرجوع إلىكيفية استخدام Aspose.Cells.GridDesktop
Aspose.Cells.GridDesktop يوفر ثلاث طرق مختلفة لفتح ملف Excel.
- فتح من ملف
- فتح ملف CSV
- الافتتاح من تيار
فتح ملف إكسل
في هذا المثال ، قم بإنشاء تطبيق سطح مكتب وقم بما يلي.
- أضف عنصر تحكم GridControl واحد إلى النموذج.
- أضف ثلاثة أزرار مع ضبط خصائص النص الخاصة بهم على النحو التالي:
- افتح ملف Excel
- افتح ملف CSV
- فتح من تيار
فتح من ملف
لتحميل المحتوى من ملف Excel إلى Aspose.Cells.GridDesktop control ، سيكون عليك استدعاء طريقة التحكم لتحديد مسار ملف Excel. بعد ذلك ، سيعثر Aspose.Cells.GridDesktop control تلقائيًا على العثور على الملف من المسار المحدد وعرض محتوياته. يتم توفير مقتطف الشفرة لتحميل محتويات ملف Excel في المثال أدناه. قم بإنشاء حدث النقر الخاص بـافتح ملف Excel زر ولصق الكود التالي بداخله.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specifying the path of Excel file using ImportExcelFile method of the control | |
gridDesktop1.ImportExcelFile(dataDir + "Sample.xlsx"); |
يمكن للمطورين استخدام مقتطف الشفرة أعلاه بأي طريقة يريدونها. على سبيل المثال ، إذا كنت تريد تحميل ملف Excel تلقائيًا عند تحميل نموذج windows ، فيمكنك إضافة هذا الرمز ضمن حدث Load للنموذج الخاص بك.
فتح ملف CSV
Aspose.Cells.GridDesktop يدعم تحميل ملف CSV أيضا. قم بإنشاء حدث النقر الخاص بـافتح ملف CSV زر ولصق الكود التالي بداخله.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Specifying the path of Excel file using ImportExcelFile method of the control | |
gridDesktop1.ImportExcelFile(dataDir + "SampleCSV1.csv"); |
الافتتاح من تيار
في مناقشتنا أعلاه ، ناقشنا حول تحميل ملف Excel باستخدام مسار الملف الخاص به ولكن Aspose.Cells. يدعم عنصر التحكم في سطح المكتب Aspose.Cells. أيضًا تحميل ملف Excel من التدفق. قم بإنشاء حدث النقر الخاص بـفتح من تيار زر ولصق الكود التالي بداخله.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Opening an Excel file as a stream | |
FileStream fs = File.OpenRead(dataDir + "Sample.xlsx"); | |
// Loading the Excel file contents into the control from a stream | |
gridDesktop1.ImportExcelFile(fs); | |
// Closing stream | |
fs.Close(); |
يعد استخدام الملف كتدفق طريقة أفضل لمنع أي نوع من الوصول إلى الملفات أو مشاركة مشكلات الانتهاك لأن هذا الأسلوب يضمن إغلاق جميع الاتصالات بالملفات عن طريق إغلاق الدفق.