Öppna olika Microsoft Excel-versionsfiler

Öppna filer av olika Microsoft Excel-versioner

En applikation måste ofta kunna öppna Microsoft Excel-filer skapade i olika versioner, till exempel Microsoft Excel 95,97, eller Microsoft Excel 2007/2010/2013/2016/2019 och Office 365 . Du kan behöva ladda en fil i något av flera format, inklusive XLS, XLSX, XLSM, XLSB, SpreadsheetML, TabDelimited eller 0761934611, 0418, 0418, 0418, 0418 och Använd konstruktorn eller använd**Arbetsbok** klass'**setFileFormat**metod för att specificera formatet med hjälp av**FileFormatType**uppräkning.

De**FileFormatType**uppräkningen innehåller många fördefinierade filformat av vilka några ges nedan.

Filformatstyper Beskrivning
CSV Representerar en CSV-fil
EXCEL_97_TO_2003 Representerar en Excel 97 - 2003-fil
XLSX Representerar en Excel 2007/2010/2013/2016/2019 och Office 365 XLSX-fil
XLSM Representerar en Excel 2007/2010/2013/2016/2019 och Office 365 XLSM-fil
XLTX Representerar en Excel 2007/2010/2013/2016/2019 och Office 365 mall XLTX fil
XLTM Representerar en Excel 2007/2010/2013/2016/2019 och Office 365 makroaktiverad XLTM-fil
XLSB Representerar en Excel 2007/2010/2013/2016/2019 och Office 365 binär XLSB fil
Kalkylblad_ML Representerar en SpreadsheetML-fil
TSV Representerar en tabbseparerad värdefil
TAB_DELIMITED Representerar en tabbavgränsad textfil
ODS Representerar en ODS-fil
HTML Representerar en HTML-fil
M_HTML Representerar en MHTML-fil

Öppnar Microsoft Excel 95/5.0-filer

För att öppna en Microsoft Excel 95/5.0-fil, använd**LoadOptions**och ställ in det relaterade attributet för**LoadOptions**klass för mallfilen som ska laddas. En exempelfil för att testa den här funktionen kan laddas ner från följande länk:

Excel95 fil

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!");

Öppnar Microsoft Excel 97 - 2003-filer

För att öppna en Microsoft Excel 97 - 2003-fil, använd**LoadOptions** och ställ in det relaterade attributet för**LoadOptions**klass för mallfilen som ska laddas.

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!");

Öppna Microsoft Excel 2007/2010/2013/2016/2019 och Office 365 XLSX filer

För att öppna ett Microsoft Excel 2007/2010/2013/2016/2019 och Office 365-format, det vill säga XLSX eller XLSB, anger du filsökvägen. Du kan också använda**LoadOptions** och ställ in relaterade attribut/alternativ för**LoadOptions**klass för mallfilen som ska laddas.

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!");

Öppna krypterade Excel-filer

Det är möjligt att skapa krypterade Excel-filer med Microsoft Excel. För att öppna en krypterad fil, använd**LoadOptions** och ställ in dess attribut och alternativ (till exempel ange ett lösenord) för mallfilen som ska laddas. En exempelfil för att testa den här funktionen kan laddas ner från följande länk:

Krypterad Excel

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 stöder även öppning av lösenordsskyddade Microsoft Excel 2007, 2010, 2013, 2016, 2019, Office 365-filer.