أول طلب Aspose.Cells - Hello World
Contents
[
Hide
]
يوضح هذا البرنامج التعليمي كيفية إنشاء أول تطبيق (Hello World) باستخدام Aspose.Cells ‘API البسيط. يقوم هذا التطبيق البسيط بإنشاء ملف Excel Microsoft بالنص “Hello World” في خلية ورقة عمل محددة.
إنشاء تطبيق Hello World
تؤدي الخطوات أدناه إلى إنشاء تطبيق Hello World باستخدام Aspose.Cells API:
- قم بإنشاء مثيل لـدفتر العمل صف دراسي.
- إذا كان لديك ترخيص ، إذنقم بتطبيقه. إذا كنت تستخدم الإصدار التقييمي ، فتخط سطور التعليمات البرمجية المتعلقة بالترخيص.
- قم بإنشاء ملف Excel جديد ، أو افتح ملف Excel موجود.
- قم بالوصول إلى أي خلية مرغوبة من ورقة العمل في ملف Excel.
- أدخل الكلماتHello World! في خلية تم الوصول إليها.
- قم بإنشاء ملف Excel Microsoft المعدل.
يتم توضيح تنفيذ الخطوات المذكورة أعلاه في الأمثلة أدناه.
نموذج التعليمات البرمجية: إنشاء مصنف جديد
المثال التالي ينشئ مصنفًا جديدًا من البداية ، يكتب Hello World! في الخلية A1 في ورقة العمل الأولى ويحفظ ملف Excel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
try | |
{ | |
// Create a License object | |
License license = new License(); | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.SetLicense(dataDir + "Aspose.Cells.lic"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Instantiate a Workbook object that represents Excel file. | |
Workbook wb = new Workbook(); | |
// When you create a new workbook, a default "Sheet1" is added to the workbook. | |
Worksheet sheet = wb.Worksheets[0]; | |
// Access the "A1" cell in the sheet. | |
Cell cell = sheet.Cells["A1"]; | |
// Input the "Hello World!" text into the "A1" cell | |
cell.PutValue("Hello World!"); | |
// Save the Excel file. | |
wb.Save(dataDir + "MyBook_out.xlsx"); |
نموذج التعليمات البرمجية: فتح ملف موجود
يفتح المثال التالي ملف قالب Excel Microsoft موجود باسم “Sample.xlsx” ، بإدخال “Hello World!” نص في الخلية A1 في ورقة العمل الأولى ويحفظ المصنف.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
try | |
{ | |
// Create a License object | |
License license = new License(); | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.SetLicense("Aspose.Cells.lic"); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "Sample.xlsx", FileMode.Open); | |
// Instantiate a Workbook object that represents the existing Excel file | |
Workbook workbook = new Workbook(fstream); | |
// Get the reference of "A1" cell from the cells collection of a worksheet | |
Cell cell = workbook.Worksheets[0].Cells["A1"]; | |
// Put the "Hello World!" text into the "A1" cell | |
cell.PutValue("Hello World!"); | |
// Save the Excel file | |
workbook.Save(dataDir + "HelloWorld_out.xlsx"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |