Diversi modi per aprire i file

Apertura di un file tramite un percorso

Gli sviluppatori possono aprire un file Excel Microsoft utilizzando il percorso del file sul computer locale specificandolo nel**Workbook**costruttore di classe. Basta passare il percorso nel costruttore come a*corda*. Aspose.Cells rileverà automaticamente il tipo di formato del file.

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

Apertura di un file tramite un flusso

È anche semplice aprire un file Excel come flusso. Per fare ciò, usa una versione sovraccaricata del costruttore che accetta ilBufferStreamoggetto che contiene il file.

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

Apertura di un file con solo dati

Per aprire un file con solo dati, utilizzare l’estensione**LoadOptions** e**[Filtro di caricamento](https://reference.aspose.com/cells/python-java/asposecells.api/Filtro di caricamento)**classes per impostare l’attributo correlato e le opzioni delle classi per il file modello da caricare.

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