ファイルを開くさまざまな方法
Contents
[
Hide
]
Aspose.Cells を使用すると、ファイルを開いてデータを取得したり、デザイナー テンプレートを使用して開発プロセスをスピードアップしたりすることが簡単になります。
パス経由でファイルを開く
開発者は、ローカル コンピューター上のファイル パスを使用して 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 ファイルをストリームとして開くのも簡単です。これを行うには、コンストラクターのオーバーロードされたバージョンを使用します。バッファストリームファイルを含むオブジェクト。
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**classes を使用して、ロードするテンプレート ファイルの関連する属性とクラスのオプションを設定します。
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() |
Aspose.Cells までにネイティブでない Excel ファイルまたはその他のファイル形式 (PPT/PPTX、DOC/DOCX など) を開こうとすると、例外がスローされます。
かなりの可能性があります**ワークブック**コンストラクターがスローする可能性があります*System.OutOfMemoryException*大きなスプレッドシートの読み込み中。この例外は、スプレッドシートをメモリに完全にロードするには使用可能なメモリが不足していることを示しているため、メモリ設定を有効にしてスプレッドシートをロードする必要があります。