ファイルを開くさまざまな方法
Contents
[
Hide
]
Aspose.Cellsを使用すると、データを取得したり、開発プロセスをスピードアップするためにデザイナーテンプレートを使用したりするために、ファイルを開くことが可能です。 Aspose.Cellsは、Microsoft Excelスプレッドシート(XLS、XLSX、XLSM、XLSB)、CSV、またはタブ区切りファイルなど、さまざまな種類のファイルを開くことができます。
パスを介してファイルを開く
開発者は、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ファイルをストリームとして開くことも可能です。 これを行うには、ファイルを含むStreamオブジェクトを使用するコンストラクタのオーバーロードバージョンを使用します。
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(); |