ファイルを開くさまざまな方法

パス経由でファイルを開く

開発者は、ローカル コンピューター上のファイル パスを使用して Microsoft Excel ファイルを開くことができます。Iワークブッククラス コンストラクタ。コンストラクターでパスを String として渡すだけです。 Aspose.Cells は、ファイル形式の種類を自動的に検出します。

//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 ファイルをストリームとして開くこともできます。これを行うには、コンストラクターのオーバーロードされたバージョンを使用します。ストリームファイルを含むオブジェクト。

//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();