حفظ الملفات

طرق مختلفة لحفظ الملفات

يوفر Aspose.Cells Workbook الذي يمثل ملف Microsoft Excel ويوفر الأساليب اللازمة للعمل مع ملفات Excel. يوفر فئة Workbook الأسلوب Save المستخدم لحفظ ملفات Excel. يحتوي أسلوب Save على العديد من التحميلات التي تُستخدم لحفظ الملفات بطرق مختلفة. يُقرر تنسيق الملف الذي يتم حفظه إليه بواسطة تعداد SaveFormat.

حفظ ملف في موقع معين

لحفظ الملفات في مكان تخزين ما، حدد اسم الملف (مع المسار التخزيني الكامل) وتنسيق الملف المطلوب (من تعداد SaveFormat) عند استدعاء أسلوب Save الكائن Workbook.

Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Source directory path
U16String dirPath(u"..\\Data\\LoadingSavingAndConverting\\");
//Output directory path
U16String outPath(u"..\\Data\\Output\\");
//Load sample Excel file
Workbook workbook(dirPath + u"sampleExcelFile.xlsx");
//Save in Excel 97-2003 format
workbook.Save(outPath + u"outputSavingFiletoSomeLocationExcel97-2003.xls");
//OR
workbook.Save(outPath + u"outputSavingFiletoSomeLocationOrExcel97-2003.xls", SaveFormat::Excel97To2003);
//Save in Excel2007 xlsx format
workbook.Save(outPath + u"outputSavingFiletoSomeLocationXlsx.xlsx", SaveFormat::Xlsx);
Aspose::Cells::Cleanup();

حفظ الملف في تدفق

لحفظ الملفات في تدفق، أنشئ كائن MemoryStream أو FileStream واحفظ الملف في ذلك الكائن تدفقًا عن طريق استدعاء أسلوب Save الكائن Workbook. حدد تنسيق الملف المطلوب باستخدام تعداد SaveFormat عند استدعاء أسلوب Save.

Aspose::Cells::Startup();
//Source directory path
U16String dirPath(u"");
//Output directory path
U16String outPath(u"");
//Load sample Excel file
Workbook workbook(dirPath + u"wdd.xlsx");
//Create FileStream object
std::ofstream fileStream(outPath.ToUtf8() + "wdd2.xlsx", std::ios::binary);
//Save the Workbook to Stream
Vector<uint8_t> stream = workbook.Save(SaveFormat::Xlsx);
fileStream.write(reinterpret_cast<char*>(stream.GetData()), stream.GetLength());
fileStream.close();
Aspose::Cells::Cleanup();

حفظ الملف إلى صيغة PDF

لحفظ المحتوى المرغوب فيه إلى ملف PDF باستخدام مكتبة Aspose.Cells for C++ ، أنشئ Workbook جديد أو قم بإنشاء Workbook عن طريق قراءة ملف Excel موجود، ثم احفظ الملف إلى صيغة PDF عن طريق استدعاء الطريقة Save من Workbook. عند استدعاء طريقة Save ، استخدم تعداد SaveFormat لتحديد الصيغة المرغوبة للملف.

Aspose::Cells::Startup();
//load/creat the Excel file
Workbook wb;
//Set cell value
wb.GetWorksheets().Get(0).GetCells().Get(u"A1").PutValue(u"test");
//Set security options using PdfSecurityOptions class
PdfSecurityOptions securityOptions;
securityOptions.SetOwnerPassword(u"123");
securityOptions.SetPrintPermission(true);
securityOptions.SetAccessibilityExtractContent(true);
//Set saving PDF parameters
PdfSaveOptions pdfSaveOptions;
pdfSaveOptions.SetSecurityOptions(securityOptions);
//Save encrypted PDF files
wb.Save("security.pdf", pdfSaveOptions);
Aspose::Cells::Cleanup();