Öffnen von verschiedenen Microsoft Excel Versionen Dateien
Wie man Dateien verschiedener Microsoft Excel-Versionen öffnet
Eine Anwendung muss oft in der Lage sein, Microsoft Excel-Dateien aus verschiedenen Versionen zu öffnen, z. B. Microsoft Excel 95, 97 oder Microsoft Excel 2007/2010/2013/2016/2019 und Office 365. Sie müssen möglicherweise eine Datei in einem der verschiedenen Formate wie XLS, XLSX, XLSM, XLSB, SpreadsheetML, tabstoppgetrennt oder TSV, CSV, ODS und so weiter laden. Verwenden Sie den Konstruktor oder geben Sie den Workbook Klassentypattribut an, das das Format mithilfe der FileFormatType Aufzählung spezifiziert.
Die FileFormatType-Enumeration enthält viele vordefinierte Dateiformate, von denen einige unten aufgeführt sind.
Dateiformat-Typen | Beschreibung |
---|---|
Csv | Stellt eine CSV-Datei dar |
Excel97To2003 | Stellt eine Excel 97 - 2003-Datei dar |
Xlsx | Stellt eine Excel 2007/2010/2013/2016/2019 und Office 365 XLSX-Datei dar |
Xlsm | Stellt eine Excel 2007/2010/2013/2016/2019 und Office 365 XLSM-Datei dar |
Xltx | Stellt eine Excel 2007/2010/2013/2016/2019 und Office 365-Vorlage XLTX-Datei dar |
Xltm | Stellt eine Excel 2007/2010/2013/2016/2019 und Office 365 makrofähige XLTM-Datei dar |
Xlsb | Stellt eine Excel 2007/2010/2013/2016/2019 und Office 365 binäre XLSB-Datei dar |
SpreadsheetML | Stellt eine SpreadsheetML-Datei dar |
Tsv | Stellt eine Tabstoppwerte-Datei dar |
TabDelimited | Stellt eine tabulatorgetrennte Textdatei dar |
Ods | Stellt eine ODS-Datei dar |
Html | Stellt eine HTML-Datei dar |
Mhtml | Stellt eine MHTML-Datei dar |
Öffnen von Microsoft Excel 95/5.0-Dateien
Um eine Microsoft Excel 95/5.0-Datei zu öffnen, verwenden Sie LoadOptions und legen das zugehörige Attribut für die LoadOptions-Klasse der zu ladenden Vorlagendatei fest. Eine Beispieldatei zur Überprüfung dieses Features können Sie von folgendem Link herunterladen:
// 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!"); | |
} |
Öffnen von Microsoft Excel 97 - 2003-Dateien
Um eine Microsoft Excel 97 - 2003-Datei zu öffnen, verwenden Sie LoadOptions und legen das zugehörige Attribut für die LoadOptions-Klasse der zu ladenden Vorlagendatei fest.
// 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!"); | |
} |
Öffnen von Microsoft Excel 2007/2010/2013/2016/2019- und Office 365 XLSX-Dateien
Um ein Microsoft Excel 2007/2010/2013/2016/2019 und Office 365-Format zu öffnen, d.h. XLSX oder XLSB, geben Sie den Dateipfad an. Sie können auch LoadOptions verwenden und die zugehörigen Attribute/Optionen der LoadOptions-Klasse der zu ladenden Vorlagendatei festlegen.
// 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!"); |
Verschlüsselte Excel-Dateien öffnen
Es ist möglich, verschlüsselte Excel-Dateien mit Microsoft Excel zu erstellen. Um eine verschlüsselte Datei zu öffnen, verwenden Sie die LoadOptions und legen deren Attribute und Optionen fest (z. B. geben Sie ein Passwort) für die zu ladende Vorlagendatei. Eine Beispieldatei zum Testen dieses Features kann über folgenden Link heruntergeladen werden:
// 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 unterstützt auch das Öffnen von passwortgeschützten Microsoft Excel 2007, 2010, 2013, 2016, 2019, Office 365-Dateien.