Apertura di file di diverse versioni di Microsoft Excel
Apertura di file di diverse versioni di Microsoft Excel
Spesso un’applicazione deve essere in grado di aprire file Microsoft Excel creati in diverse versioni, ad esempio Microsoft Excel 95, 97, o Microsoft Excel 2007/2010/2013/2016/2019 e Office 365. Potrebbe essere necessario caricare un file in uno dei vari formati, tra cui XLS, XLSX, XLSM, XLSB, SpreadsheetML, tabulati o TSV, CSV, ODS e così via. Utilizzare il costruttore, o specificare il metodo setFileFormat della classe Workbook per specificare il formato utilizzando l’enumerazione FileFormatType.
L’enumerazione FileFormatType contiene molti formati di file predefiniti alcuni dei quali sono elencati di seguito.
Tipi di formato file | Descrizione |
---|---|
CSV | Rappresenta un file CSV |
EXCEL_97_TO_2003 | Rappresenta un file Excel 97 - 2003 |
XLSX | Rappresenta un file XLSX Excel 2007/2010/2013/2016/2019 e Office 365 |
XLSM | Rappresenta un file XLSM Excel 2007/2010/2013/2016/2019 e Office 365 |
XLTX | Rappresenta un file modello XLTX di Excel 2007/2010/2013/2016/2019 e Office 365 |
XLTM | Rappresenta un file XLTM abilitato per macro di Excel 2007/2010/2013/2016/2019 e Office 365 |
XLSB | Rappresenta un file XLSB binario Excel 2007/2010/2013/2016/2019 e Office 365 |
SPREADSHEET_ML | Rappresenta un file SpreadsheetML |
TSV | Rappresenta un file di valori separati da tabulazione |
TAB_DELIMITED | Rappresenta un file di testo delimitato da tabulazioni |
ODS | Rappresenta un file ODS |
HTML | Rappresenta un file HTML |
M_HTML | Rappresenta un file MHTML |
Apertura di file Microsoft Excel 95/5.0
Per aprire un file Microsoft Excel 95/5.0, utilizzare LoadOptions e impostare l’attributo correlato per la classe LoadOptions per il file del modello da caricare. È possibile scaricare un file di esempio per testare questa funzionalità dal seguente link:
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook, LoadOptions, LoadFormat | |
from jpype import java | |
# Get the Excel file into stream | |
fis = java.io.FileInputStream("Excel95.xls") | |
# Instantiate LoadOptions specified by the LoadFormat. | |
loadOptions = LoadOptions(LoadFormat.EXCEL_97_TO_2003) | |
# Create a Workbook object and opening the file from the stream | |
wbExcel95 = Workbook(fis, loadOptions); | |
print("Microsoft Excel 95/5.0 workbook opened successfully!") |
Apertura dei file Microsoft Excel 97 - 2003
Per aprire un file Microsoft Excel 97 - 2003, utilizzare LoadOptions e impostare l’attributo correlato per la classe LoadOptions per il file del modello da caricare.
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook, LoadOptions, LoadFormat | |
from jpype import java | |
# Get the Excel file into stream | |
fis = java.io.FileInputStream("Excel03.xls") | |
# Instantiate LoadOptions specified by the LoadFormat. | |
loadOptions = LoadOptions(LoadFormat.EXCEL_97_TO_2003) | |
# Create a Workbook object and opening the file from the stream | |
wbExcel03 = Workbook(fis, loadOptions); | |
print("Microsoft Excel 97 - 2003 workbook opened successfully!") |
Apertura dei file Microsoft Excel 2007/2010/2013/2016/2019 e Office 365 XLSX
Per aprire un file Microsoft Excel 2007/2010/2013/2016/2019 e Office 365, cioè XLSX o XLSB, specificare il percorso del file. È inoltre possibile utilizzare LoadOptions e impostare gli attributi/opzioni correlati della classe LoadOptions per il file del modello da caricare.
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook, LoadOptions, LoadFormat | |
# The path to the documents directory. | |
dataDir = "" | |
# Opening Microsoft Excel 2007 Xlsx Files | |
loadOptions2 = LoadOptions(LoadFormat.XLSX) | |
# Create a Workbook object and opening the file from its path | |
wbExcel07 = Workbook(dataDir + "Input.xlsx", loadOptions2) | |
print("Microsoft Excel 2007 - Office365 workbook opened successfully!") | |
jpype.shutdownJVM() |
Apertura di file Excel criptati
È possibile creare file Excel crittografati utilizzando Microsoft Excel. Per aprire un file crittografato, utilizzare LoadOptions e impostare i suoi attributi e opzioni (ad esempio, fornire una password) per il file del modello da caricare. Un file di esempio per testare questa funzionalità può essere scaricato dal seguente link:
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook, LoadOptions, LoadFormat | |
# The path to the documents directory. | |
dataDir = "" | |
# Opening Microsoft Excel 2007 Xlsx Files | |
loadOptions = LoadOptions(LoadFormat.XLSX) | |
# Specify the password | |
loadOptions.setPassword("1234") | |
# Create a Workbook object and opening the file from its path | |
wbEncrypted = Workbook(dataDir + "EncryptedExcel.xlsx", loadOptions) | |
print("Encrypted excel file opened successfully!") | |
jpype.shutdownJVM() |
Aspose.Cells supporta anche l’apertura di file Microsoft Excel 2007, 2010, 2013, 2016, 2019 e Office 365 protetti da password.