打开文件的不同方式
Contents
[
Hide
]
使用Aspose.Cells可以打开文件,例如检索数据,或者使用设计模板加速开发过程。Aspose.Cells可以打开多种不同类型的文件,如Microsoft Excel电子表格(XLS、XLSX、XLSM、XLSB)、CSV或Tab分隔文件。
通过路径打开文件
开发人员可以通过在 Workbook 类构造函数中对其指定的本地计算机上的文件路径来打开 Microsoft Excel 文件。 只需在构造函数中传递路径即可。Aspose.Cells 将自动检测文件格式类型。
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
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
Aspose::Cells::Startup(); | |
//Source directory path | |
U16String dirPath(u"..\\Data\\LoadingSavingAndConverting\\"); | |
//Create Workbook object from an Excel file path | |
Workbook workbook(dirPath + u"sampleExcelFile.xlsx"); | |
//Show following message on console | |
std::cout << "Workbook opened successfully using file path." << std::endl; | |
Aspose::Cells::Cleanup(); |
使用流打开文件
也可以将 Excel 文件作为流打开。 为此,请使用接受包含文件的 流 对象的构造函数的重载版本。
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
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
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\\"); | |
//You need to write your own code to read the contents of the sampleExcelFile.xlsx file into this variable. | |
Vector<uint8_t> FileStream{ 0 }; //"sampleExcelFile.xlsx" | |
//Create Workbook object from a Stream object | |
Workbook workbook(FileStream); | |
//Show following message on console | |
std::cout << "Workbook opened successfully using stream." << std::endl; | |
Aspose::Cells::Cleanup(); |