Apri diversi file di Microsoft Excel in versioni diverse

Come aprire file di diverse versioni di Microsoft Excel

Un’applicazione deve spesso essere in grado di aprire file di 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 diversi formati, tra cui XLS, XLSX, XLSM, XLSB, SpreadsheetML, tabella delimitata o TSV, CSV, ODS e così via. Utilizzare il costruttore, o specificare l’attributo di tipo della classe Workbook che specifica 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
Excel97To2003 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 macro abilitato di Excel 2007/2010/2013/2016/2019 e Office 365
Xlsb Rappresenta un file XLSB binario di Excel 2007/2010/2013/2016/2019 e Office 365
SpreadsheetML Rappresenta un file SpreadsheetML
Tsv Rappresenta un file di valori separati da tabulazioni
TabDelimited Rappresenta un file di testo delimitato da tabulazioni
Ods Rappresenta un file ODS
Html Rappresenta un file HTML
Mhtml Rappresenta un file MHTML

Apri 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:

File di Excel95

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Get the Excel file into stream
using (FileStream stream = new FileStream(dataDir + "Excel95_5.0.xls", FileMode.Open))
{
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions1 = new LoadOptions(LoadFormat.Excel97To2003);
// Create a Workbook object and opening the file from the stream
Workbook wbExcel95 = new Workbook(stream, loadOptions1);
Console.WriteLine("Microsoft Excel 95/5.0 workbook opened successfully!");
}

Apri 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.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Get the Excel file into stream
using (FileStream stream = new FileStream(dataDir + "Book_Excel97_2003.xls", FileMode.Open))
{
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions1 = new LoadOptions(LoadFormat.Excel97To2003);
// Create a Workbook object and opening the file from the stream
Workbook wbExcel97 = new Workbook(stream, loadOptions1);
Console.WriteLine("Microsoft Excel 97 - 2003 workbook opened successfully!");
}

Apri file XLSX di Microsoft Excel 2007/2010/2013/2016/2019 e Office 365

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.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Opening Microsoft Excel 2007 Xlsx Files
// Instantiate LoadOptions specified by the LoadFormat.
LoadOptions loadOptions2 = new LoadOptions(LoadFormat.Xlsx);
// Create a Workbook object and opening the file from its path
Workbook wbExcel2007 = new Workbook(dataDir + "Book_Excel2007.xlsx", loadOptions2);
Console.WriteLine("Microsoft Excel 2007 - Office365 workbook opened successfully!");

Apri 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:

Encrypted Excel

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate LoadOptions
LoadOptions loadOptions6 = new LoadOptions();
// Specify the password
loadOptions6.Password = "1234";
// Create a Workbook object and opening the file from its path
Workbook wbEncrypted = new Workbook(dataDir + "encryptedBook.xls", loadOptions6);
Console.WriteLine("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.