Öffnen von verschiedenen Microsoft Excel Versionen Dateien
Öffnen von Dateien verschiedener Microsoft Excel-Versionen
Eine Anwendung muss oft in der Lage sein, Microsoft Excel-Dateien in verschiedenen Versionen zu öffnen, z. B. Microsoft Excel 95, 97 oder Microsoft Excel 2007/2010/2013/2016/2019 und Office 365. Möglicherweise müssen Sie eine Datei in einem der verschiedenen Formate laden, darunter XLS, XLSX, XLSM, XLSB, SpreadsheetML, Tab-getrennt oder TSV, CSV, ODS und so weiter. Verwenden Sie den Konstruktor oder geben Sie die Methode der Klasse Workbook an, um das Format mit der setFileFormat-Enumeration anzugeben.
Die FileFormatType-Enumeration enthält viele vordefinierte Dateiformate, von denen einige unten aufgeführt sind.
Dateiformat-Typen | Beschreibung |
---|---|
CSV | Repräsentiert eine CSV-Datei |
EXCEL_97_TO_2003 | Repräsentiert eine Excel 97 - 2003 Datei |
XLSX | Repräsentiert eine Excel 2007/2010/2013/2016/2019 und Office 365 XLSX-Datei |
XLSM | Repräsentiert eine Excel 2007/2010/2013/2016/2019 und Office 365 XLSM-Datei |
XLTX | Repräsentiert eine Excel 2007/2010/2013/2016/2019 und Office 365 Vorlagen-XLTX-Datei |
XLTM | Repräsentiert eine Excel 2007/2010/2013/2016/2019 und Office 365 makrofähige XLTM-Datei |
XLSB | Repräsentiert eine Excel 2007/2010/2013/2016/2019 und Office 365 binäre XLSB-Datei |
SPREADSHEET_ML | Repräsentiert eine SpreadsheetML-Datei |
TSV | Repräsentiert eine durch Tabulatoren getrennte Werte-Datei |
TAB_DELIMITED | Repräsentiert eine tabulatorgetrennte Textdatei |
ODS | Repräsentiert eine ODS-Datei |
HTML | Repräsentiert eine HTML-Datei |
M_HTML | Repräsentiert eine MHTML-Datei |
Öffnen von Microsoft Excel 95/5.0-Dateien
Um eine Datei von Microsoft Excel 95/5.0 zu öffnen, verwenden Sie LoadOptions und setzen Sie das zugehörige Attribut für die Klasse LoadOptions für die zu ladende Vorlagendatei. Eine Beispieldatei zur Überprüfung dieses Features kann über den folgenden Link heruntergeladen werden:
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!") |
Öffnen von Microsoft Excel 97 - 2003-Dateien
Um eine Datei von Microsoft Excel 97 - 2003 zu öffnen, verwenden Sie LoadOptions und setzen Sie das zugehörige Attribut für die Klasse LoadOptions für die zu ladende Vorlagendatei.
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!") |
Ö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, d.h. XLSX oder XLSB, zu öffnen, geben Sie den Dateipfad an. Sie können auch LoadOptions verwenden und das zugehörige Attribut/Optionen der Klasse LoadOptions für die zu ladende Vorlagendatei festlegen.
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() |
Öffnen verschlüsselter Excel-Dateien
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:
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 unterstützt auch das Öffnen von passwortgeschützten Microsoft Excel 2007, 2010, 2013, 2016, 2019, Office 365-Dateien.