Olika sätt att öppna filer
Öppna en fil via en sökväg
Utvecklare kan öppna en Microsoft Excel-fil med hjälp av dess sökväg på den lokala datorn genom att specificera det i konstruktorn för Workbookklassen. Skicka helt enkelt sökvägen i konstruktorn som en sträng. Aspose.Cells kommer automatiskt att upptäcka filformatet.
//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(); |
Öppna en fil med hjälp av en ström
Det är också möjligt att öppna en Excel-fil som en ström. För att göra det, använd en överlagrad version av konstruktorn som tar emot Streamobjektet som innehåller filen.
//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(); |