البدء
التثبيت
تثبيت Aspose Cells من خلال NuGet
NuGet هو أسهل طريقة لتنزيل وتثبيت Aspose.Cells for C++.
- إنشاء مشروع Microsoft Visual Studio لـ C++.
- تضمين ملف الرأس “Aspose.Cells.h”.
- فتح Microsoft Visual Studio ومدير حزمة NuGet.
- البحث عن “aspose.cells.cpp” للعثور على Aspose.Cells for C++ المطلوبة.
- انقر فوق “تثبيت”، سيتم تنزيل Aspose.Cells for C++ والإشارة إليه في مشروعك.
يمكنك أيضًا تنزيله من صفحة الويب nuget ل aspose.cells: حزمة NuGet لـ Aspose.Cells for C++
عرض توضيحي لاستخدام Aspose.Cells for C++ على Windows
- قم بتنزيل Aspose.Cells for C++ من الصفحة التالية: تنزيل Aspose.Cells for C++(Windows)
- قم بفك الضغط عن الحزمة وستجد مثالًا حول كيفية استخدام Aspose.Cells for C++.
- افتح ملف example.sln باستخدام Visual Studio 2017 أو أحدث.
- main.cpp: يظهر هذا الملف كيفية كتابة الاختبار لـ Aspose.Cells for C++.
عرض توضيحي لاستخدام Aspose.Cells for C++ على Linux.
- قم بتنزيل Aspose.Cells for C++ من الصفحة التالية: تنزيل Aspose.Cells for C++ (Linux)
- قم بفك الضغط عن الحزمة وستجد مثالًا حول كيفية استخدام Aspose.Cells for C++ على Linux.
- تأكد من أنك في المسار الذي يقع فيه المثال.
- قم بتشغيل “cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release”
- قم بتشغيل “cmake –build example/build”
عرض توضيحي لاستخدام Aspose.Cells for C++ على نظام Mac OS.
- قم بتنزيل Aspose.Cells for C++ من الصفحة التالية: تنزيل Aspose.Cells for C++ (MacOS)
- قم بفك الضغط عن الحزمة وستجد مثالًا حول كيفية استخدام Aspose.Cells for C++ على نظام MacOS.
- تأكد من أنك في المسار الذي يقع فيه المثال.
- قم بتشغيل “cmake -S example -B example/build -DCMAKE_BUILD_TYPE=Release”
- قم بتشغيل “cmake –build example/build”
إنشاء تطبيق مرحبًا بالعالم
تقوم الخطوات التالية بإنشاء تطبيق مرحبًا بالعالم باستخدام واجهة برمجة التطبيقات لـ Aspose.Cells:
- أنشئ نسخة من فئة Workbook.
- إذا كان لديك ترخيص، ثم قم بتطبيقه. إذا كنت تستخدم النسخة التجريبية، فتخطى خطوط الكود المتعلقة بالترخيص. ١. الوصول إلى أي خلية مرغوبة في ورقة العمل في ملف إكسل.
- أدخل عبارة “مرحبًا بالعالم!” في الخلية المستخدمة.
- إنشاء ملف Microsoft Excel المعدل.
يتم توضيح تنفيذ الخطوات أعلاه في الأمثلة أدناه.
مثال على الشفرة: إنشاء مصنف جديد
المثال التالي يقوم بإنشاء مصنف جديد من البداية، يقوم بإدراج “مرحبًا بالعالم!” في الخلية A1 في ورقة العمل الأولى، ويحفظ ملف Excel.
#include "Aspose.Cells.h" | |
using namespace Aspose::Cells; | |
int main(void) | |
{ | |
Aspose::Cells::Startup(); | |
try | |
{ | |
// Create a License object | |
License license; | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
license.SetLicense(u"Aspose.Cells.lic"); | |
// Instantiate a Workbook object that represents Excel file. | |
Workbook wb; | |
// When you create a new workbook, a default "Sheet1" is added to the workbook. | |
Worksheet sheet = wb.GetWorksheets().Get(0); | |
// Access the "A1" cell in the sheet. | |
Cell cell = sheet.GetCells().Get(u"A1"); | |
// Input the "Hello World!" text into the "A1" cell | |
cell.PutValue(u"Hello World!"); | |
// Save the Excel file. | |
wb.Save(u"MyBook_out.xlsx"); | |
} | |
catch (const CellsException& ex) | |
{ | |
std::cout << ex.GetErrorMessage().ToUtf8() << std::endl; | |
} | |
Aspose::Cells::Cleanup(); | |
} |
مثال على الشفرة: فتح ملف موجود
المثال التالي يفتح ملف قالب Microsoft Excel موجود، يحصل على خلية ويتحقق من القيمة في الخلية A1.
#include "Aspose.Cells.h" | |
using namespace Aspose::Cells; | |
/*Check result*/ | |
#define EXPECT_TRUE(condition) \ | |
if (condition) printf("--%s,line:%d -> Ok --\n", __FUNCTION__, __LINE__); \ | |
else printf("--%s,line:%d->>>> Failed!!!! <<<<--\n", __FUNCTION__, __LINE__); | |
int main(void) | |
{ | |
Aspose::Cells::Startup(); | |
try | |
{ | |
// Create a License object | |
License license; | |
// Set the license of Aspose.Cells to avoid the evaluation limitations | |
//license.SetLicense(u"Aspose.Cells.lic"); | |
// Instantiate a Workbook object that represents Excel file. | |
Workbook wb;//(u"MyBook_out.xlsx"); | |
// When you create a new workbook, a default "Sheet1" is added to the workbook. | |
Worksheet sheet = wb.GetWorksheets().Get(0); | |
// Access the "A1" cell in the sheet. | |
Cell cell = sheet.GetCells().Get(u"A1"); | |
U16String strRet = cell.GetStringValue(); | |
//check value | |
EXPECT_TRUE(strRet == u"Hello World!"); | |
// Save the Excel file. | |
wb.Save(u"MyBook_out.xlsx"); | |
} | |
catch (const CellsException& ex) | |
{ | |
std::cout << ex.GetErrorMessage().ToUtf8() << std::endl; | |
} | |
Aspose::Cells::Cleanup(); | |
} |