Apertura di file di diverse versioni di Microsoft Excel
Apertura di file di diverse versioni di Microsoft Excel
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. Potresti aver bisogno di caricare un file in uno qualsiasi dei diversi formati, inclusi XLS, XLSX, XLSM, XLSB, SpreadsheetML, TabDelimited o TSV, CSV, ODS e così via. Usa il costruttore, o utilizza il metodo setFileFormat della classe Workbook per specificare il formato usando 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 di Microsoft Excel 95/5.0, utilizza LoadOptions e imposta l’attributo relativo per la classe LoadOptions per il file modello da caricare. Un file di esempio per testare questa funzionalità può essere scaricato dal seguente link:
import com.aspose.cells.Workbook; | |
import com.aspose.cells.LoadOptions; | |
import com.aspose.cells.LoadFormat; | |
import java.io.FileInputStream; | |
// Get the Excel file into stream | |
var fis = new FileInputStream("Excel95.xls"); | |
// Instantiate LoadOptions specified by the LoadFormat. | |
LoadOptions options = new LoadOptions(LoadFormat.EXCEL_97_TO_2003); | |
// Create a Workbook object and opening the file from the stream | |
var workbook = new Workbook(fis, options); | |
System.out.println("Microsoft Excel 95/5.0 workbook opened successfully!"); |
Apertura dei file Microsoft Excel 97 - 2003
Per aprire un file di Microsoft Excel 97 - 2003, utilizza LoadOptions e imposta l’attributo relativo per la classe LoadOptions per il file modello da caricare.
import com.aspose.cells.Workbook; | |
import com.aspose.cells.LoadOptions; | |
import com.aspose.cells.LoadFormat; | |
import java.io.FileInputStream; | |
// Get the Excel file into stream | |
var fis = new FileInputStream("Excel03.xls"); | |
// Instantiate LoadOptions specified by the LoadFormat. | |
LoadOptions options = new LoadOptions(LoadFormat.EXCEL_97_TO_2003); | |
// Create a Workbook object and opening the file from the stream | |
var workbook = new Workbook(fis, options); | |
System.out.println("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 in formato Microsoft Excel 2007/2010/2013/2016/2019 e Office 365, cioè XLSX o XLSB, specifica il percorso del file. Puoi anche utilizzare LoadOptions e impostare l’attributo/opzioni correlati della classe LoadOptions per il file modello da caricare.
import com.aspose.cells.Workbook; | |
import com.aspose.cells.LoadOptions; | |
import com.aspose.cells.LoadFormat; | |
import java.io.FileInputStream; | |
// The path to the documents directory. | |
var dataDir = ""; | |
// Opening Microsoft Excel 2007 Xlsx Files | |
LoadOptions loadOptions2 = new LoadOptions(LoadFormat.XLSX); | |
// Create a Workbook object and opening the file from its path | |
var wbExcel07 = new Workbook(dataDir + "Input.xlsx", loadOptions2); | |
System.out.println("Microsoft Excel 2007 - Office365 workbook opened successfully!"); |
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 com.aspose.cells.Workbook; | |
import com.aspose.cells.LoadOptions; | |
import com.aspose.cells.LoadFormat; | |
import java.io.FileInputStream; | |
// The path to the documents directory. | |
var dataDir = ""; | |
// Opening Microsoft Excel 2007 Xlsx Files | |
LoadOptions loadOptions2 = new LoadOptions(LoadFormat.XLSX); | |
// Specify the password | |
loadOptions2.setPassword("1234"); | |
// Create a Workbook object and opening the file from its path | |
var wbEncrypted = new Workbook(dataDir + "EncryptedExcel.xlsx", loadOptions2); | |
System.out.println("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.