ファイルを開くさまざまな方法
Contents
[
Hide
]
Aspose.Cells for Python via .NETを使えば、ファイルを簡単に開くことができ、データの取得やデザイナーテンプレートを使った開発の高速化も可能です。
パスを使用してExcelファイルを開く方法
開発者は、ローカルコンピュータのファイルパスを指定して、Workbookクラスのコンストラクターを使用してMicrosoft Excelファイルを開くことができます。パスを文字列として渡すだけです。Aspose.Cells for Python via .NETは自動的にファイル形式を検出します。
This file contains hidden or 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
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Opening through Path | |
# Creating a Workbook object and opening an Excel file using its file path | |
workbook1 = Workbook(dataDir + "Book1.xlsx") | |
print("Workbook opened using path successfully!") |
ストリームを使用してExcelファイルを開く方法
また、ストリームとしてExcelファイルを開くことも簡単です。ファイルを含むStreamオブジェクトを引数に取るコンストラクタのオーバーロードバージョンを使用します。
This file contains hidden or 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
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Opening through Stream | |
# Create a Stream object | |
fstream = open(dataDir + "Book2.xls", "rb") | |
# Creating a Workbook object, open the file from a Stream object | |
# That contains the content of file and it should support seeking | |
workbook2 = Workbook(fstream) | |
print("Workbook opened using stream successfully!") | |
fstream.close() |
データだけを含むファイルを開く方法
データのみを含むファイルを開くには、関連する属性とオプションを設定するために、LoadOptionsおよびLoadFilterクラスを使用して、ロードするテンプレートファイルのクラスの関連属性とオプションを設定してください。
This file contains hidden or 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
from aspose.cells import LoadDataFilterOptions, LoadFilter, LoadFormat, LoadOptions, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Load only specific sheets with data and formulas | |
# Other objects, items etc. would be discarded | |
# Instantiate LoadOptions specified by the LoadFormat | |
loadOptions = LoadOptions(LoadFormat.XLSX) | |
# Set LoadFilter property to load only data & cell formatting | |
loadOptions.load_filter = LoadFilter(LoadDataFilterOptions.CELL_DATA) | |
# Create a Workbook object and opening the file from its path | |
book = Workbook(dataDir + "Book1.xlsx", loadOptions) | |
print("File data imported successfully!") |