Apertura di file di diverse versioni di Microsoft Excel
Apertura di file di diverse versioni di Microsoft Excel
Un’applicazione spesso 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 qualsiasi dei vari formati, inclusi XLS, XLSX, XLSM, XLSB, SpreadsheetML, TabDelimited or TSV, CSV, ODS e così via. Utilizzare il costruttore, o specificare l’attributo di tipo file_format della classe Workbook utilizzando l’enumerazione FileFormatType.
L’enumerazione FileFormatType contiene molti formati file predefiniti, alcuni dei quali sono riportati 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 |
XLTX | Rappresenta un file XLTM abilitato per macro 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.
import aspose.cells | |
import aspose.pyio | |
from aspose.cells import Workbook, LoadOptions, LoadFormat | |
from aspose.pyio import BufferStream | |
# Get the Excel file into stream | |
with open('Excel95.xls', 'rb') as f: | |
data = f.read() | |
databuff = BufferStream(data) | |
# 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(databuff, 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 relativo per la classe LoadOptions per il file del modello da caricare.
import aspose.cells | |
import aspose.pyio | |
from aspose.cells import Workbook, LoadOptions, LoadFormat | |
from aspose.pyio import BufferStream | |
# Get the Excel file into stream | |
with open('Excel03.xls', 'rb') as f: | |
data = f.read() | |
databuff = BufferStream(data) | |
# 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(databuff, 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 formato Microsoft Excel 2007/2010/2013/2016/2019 e Office 365, cioè XLSX o XLSB, specificare il percorso del file. È anche possibile utilizzare LoadOptions e impostare l’attributo/opzioni correlati della classe LoadOptions per il file del modello da caricare.
import aspose.cells | |
from aspose.cells 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!") |
Apertura di file Excel criptati
È possibile creare file Excel criptati utilizzando Microsoft Excel. Per aprire un file criptato, utilizzare LoadOptions e impostare i relativi attributi e opzioni (ad esempio, dare una password) per il file del modello da caricare. Un file di esempio per testare questa funzionalità può essere scaricato dal seguente link:
import aspose.cells | |
from aspose.cells 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.password = "1234" | |
# Create a Workbook object and opening the file from its path | |
wbEncrypted = Workbook(dataDir + "EncryptedExcel.xlsx", loadOptions) | |
print("Encrypted excel file opened successfully!") |
Aspose.Cells supporta anche l’apertura di file Microsoft Excel 2007, 2010, 2013, 2016, 2019 e Office 365 protetti da password.