读写 XLSM 文件格式
Contents
[
Hide
]
可能的使用场景
Microsoft Excel 支持多种格式,如 XLS、XLSX、XLSM、XLSB、CSV 等。Aspose.Cells 也支持其中的许多格式。本文介绍如何使用Aspose.Cells读写XLSM格式的excel文件。
读写 XLSM 文件格式
下面的示例代码加载源文件 XLSM并读取其单元格 A1,然后将其内容复制到单元格 C4 并将其另存为输出 XLSM 文件.
示例代码
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-C | |
//Source directory path | |
StringPtr dirPath = new String("..\\Data\\LoadingSavingAndConverting\\"); | |
//Output directory path | |
StringPtr outPath = new String("..\\Data\\Output\\"); | |
//Path of input excel file | |
StringPtr srcReadWriteXLSM = dirPath->StringAppend(new String("srcReadWriteXLSM.xlsm")); | |
//Path of output excel file | |
StringPtr outReadWriteXLSM = outPath->StringAppend(new String("outReadWriteXLSM.xlsm")); | |
//Read source xlsm file | |
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook(srcReadWriteXLSM); | |
//Access first worksheet | |
intrusive_ptr<IWorksheet> ws = wb->GetIWorksheets()->GetObjectByIndex(0); | |
//Access cell A1 | |
intrusive_ptr<ICell> cell = ws->GetICells()->GetObjectByIndex(new String("A1")); | |
//Get the string value of cell A1 | |
StringPtr strVal = cell->GetStringValue(); | |
//Print the string value of cell A1 | |
StringPtr cellValue = new String("Cell Value: "); | |
Console::WriteLine(cellValue->StringAppend(strVal)); | |
//Access cell C4 | |
cell = ws->GetICells()->GetObjectByIndex(new String("C4")); | |
//Put the string value of cell A1 into C4 | |
intrusive_ptr<String> strValPtr = new String(strVal); | |
cell->PutValue(strValPtr); | |
//Save the workbook in XLSM format | |
wb->Save(outReadWriteXLSM, SaveFormat_Xlsm); |