Dosyaları Açmanın Farklı Yolları
Yoluyla Bir Dosyayı Açma
Geliştiriciler, yerel bilgisayardaki dosya yolunu Workbook sınıf oluşturucusuna belirterek bir Microsoft Excel dosyasını açabilirler. Yalnızca yolunuzu dize olarak oluşturucusuna iletin. Aspose.Cells, dosya biçim türünü otomatik olarak algılar.
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() |
Bir Akış Yoluyla Bir Dosyayı Açma
Bir Excel dosyasını akış olarak açmak da basittir. Bunu yapmak için dosyayı içeren BufferStream nesnesini alan yapıcı işlevinin aşırı yüklenmiş bir sürümünü kullanın.
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() |
Sadece Veriyle Bir Dosyayı Açma
Yalnızca veri ile bir dosyayı açmak için, ilgili sınıfların öznitelik ve seçeneklerini ayarlamak için LoadOptions ve LoadFilter sınıflarını kullanın.
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() |