ファイルを開くさまざまな方法
Contents
[
Hide
]
Aspose.Cells を使用すると、ファイルを開いてデータを取得したり、デザイナー テンプレートを使用して開発プロセスを高速化したりすることができます。 Aspose.Cells は、Microsoft Excel スプレッドシート (XLS、XLSX、XLSM、XLSB)、CSV または TabDelimited ファイルなど、さまざまなファイルを開くことができます。
パス経由でファイルを開く
開発者は、ローカル コンピューター上のファイル パスを使用して Microsoft Excel ファイルを開くことができます。Iワークブッククラス コンストラクタ。コンストラクターでパスを String として渡すだけです。 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 | |
//Source directory path | |
StringPtr dirPath = new String("..\\Data\\LoadingSavingAndConverting\\"); | |
//Create Workbook object from an Excel file path | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(dirPath->StringAppend(new String("sampleExcelFile.xlsx"))); | |
//Show following message on console | |
Console::WriteLine(new String("Workbook opened successfully using file path.")); |
ストリームを使用してファイルを開く
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 | |
//Source directory path | |
StringPtr dirPath = new String("..\\Data\\LoadingSavingAndConverting\\"); | |
//Create a Stream object | |
intrusive_ptr<FileStream> fstream = new FileStream(dirPath->StringAppend(new String("sampleExcelFile.xlsx")), FileMode_Open); | |
//Create Workbook object from a Stream object | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(fstream); | |
//Show following message on console | |
Console::WriteLine(new String("Workbook opened successfully using stream.")); | |
//Close the Stream object | |
fstream->Close(); |