ファイルを開くさまざまな方法
Contents
[
Hide
]
Aspose.Cellsを使用すれば、たとえばデータを取得したり、開発プロセスを高速化するためのデザイナー テンプレートを使用したりするために、ファイルを開くことは簡単です。
パスを介してファイルを開く
開発者は、stringとしてパスをコンストラクタに指定することで、ローカルコンピュータ上の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
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook | |
# Opening a File via a Path | |
# The path to the documents directory. | |
dataDir = "" | |
# Opening through Path | |
# Creating a Workbook object and opening an Excel file using its file path | |
workbook = Workbook(dataDir + "Input.xlsx") | |
print("Workbook opened using path successfully!") | |
jpype.shutdownJVM() |
ストリームを介してファイルを開く
Excelファイルをストリームとして簡単に開くこともできます。ファイルを含むBufferStreamオブジェクトを使用するオーバーロードされたコンストラクターを使用します。
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
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook | |
from jpype import java | |
fis = java.io.FileInputStream("Input.xlsx") | |
workbook = Workbook(fis) | |
print("Workbook opened using stream successfully!!") | |
workbook.save("Output.pdf") | |
fis.close() | |
jpype.shutdownJVM() |
データのみでファイルを開く
データのみを含むファイルを開くには、関連する属性とオプションを設定するために、LoadOptionsおよびLoadFilterクラスを使用して、ロードするテンプレートファイルのクラスの関連属性とオプションを設定してください。
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
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook, LoadOptions, LoadFormat, LoadFilter, LoadDataFilterOptions | |
# Opening a File with Data only | |
# The path to the documents directory. | |
dataDir = "" | |
# 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.setLoadFilter(LoadFilter(LoadDataFilterOptions.CELL_DATA)) | |
# Create a Workbook object and opening the file from its path | |
workbook = Workbook(dataDir + "Input.xlsx", loadOptions) | |
print("File data imported successfully!") | |
jpype.shutdownJVM() |
大規模なスプレッドシートをロードする際に、{0}コンストラクタがSystem.OutOfMemoryExceptionをスローする可能性がかなり高いです。この例外は、利用可能なメモリが不十分であるため、スプレッドシート全体を完全にメモリに読み込むことができず、メモリ設定を有効にしてスプレッドシートをロードする必要があることを示しています。
Workbookコンストラクタが大規模なスプレッドシートをロードする際にSystem.OutOfMemoryExceptionをスローする可能性がかなり高いです。この例外は、利用可能なメモリが不足していることを示しており、スプレッドシートを完全にロードするために必要なメモリが不足している可能性があるため、メモリ設定を有効にしてスプレッドシートをロードする必要があります。