قراءة وكتابة تنسيق ملف XLSM
Contents
[
Hide
]
سيناريوهات الاستخدام المحتملة
تدعم Microsoft Excel العديد من التنسيقات مثل XLS وXLSX وXLSM وXLSB وCSV، وما إلى ذلك. كما تدعم Aspose.Cells العديد من هذه التنسيقات. يشرح هذا المقال كيفية قراءة وكتابة ملف Excel بتنسيق XLSM باستخدام Aspose.Cells.
قراءة وكتابة تنسيق ملف XLSM
يقوم الكود المصدري التالي بتحميل ملف XLSM المصدر وقراءة خلية A1 ومن ثم نسخ محتوياتها إلى الخلية C4 وحفظها باسم ملف XLSM الناتج.
الكود المثالي
This file contains 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
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\\"); | |
//Path of input excel file | |
U16String srcReadWriteXLSM = dirPath + u"srcReadWriteXLSM.xlsm"; | |
//Path of output excel file | |
U16String outReadWriteXLSM = outPath + u"outReadWriteXLSM.xlsm"; | |
//Read source xlsm file | |
Workbook wb(srcReadWriteXLSM); | |
//Access first worksheet | |
Worksheet ws = wb.GetWorksheets().Get(0); | |
//Access cell A1 | |
Cell cell = ws.GetCells().Get(u"A1"); | |
//Get the string value of cell A1 | |
U16String strVal = cell.GetStringValue(); | |
//Print the string value of cell A1 | |
U16String cellValue(u"Cell Value: "); | |
std::cout<<cellValue.ToUtf8() << strVal.ToUtf8() << std::endl; | |
//Access cell C4 | |
cell = ws.GetCells().Get(u"C4"); | |
//Put the string value of cell A1 into C4 | |
U16String strValPtr(strVal); | |
cell.PutValue(strValPtr); | |
//Save the workbook in XLSM format | |
wb.Save(outReadWriteXLSM, SaveFormat::Xlsm); | |
Aspose::Cells::Cleanup(); |