Öppna olika Microsoft Excel versioners filer
Hur man öppnar 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 TSV, CSV, ODS och så vidare. Använd konstruktören, eller ange Workbook class' FileFormat typ attribut som anger formatet med hjälp av FileFormatType uppräkningen.
FileFormatTypeuppräkningen innehåller många fördefinierade filformat varav några ges nedan.
Filtyp | Beskrivning |
---|---|
Csv | Representerar en CSV-fil |
Excel97To2003 | 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 |
SpreadsheetML | Representerar en SpreadsheetML fil |
Tsv | Representerar en tabb-separerad värden fil |
TabDelimited | Representerar en Tabbavgränsad textfil |
Ods | Representerar en ODS fil |
Html | Representerar en HTML fil |
Mhtml | Representerar en MHTML fil |
Öppna Microsoft Excel 95/5.0 filer
För att öppna en Microsoft Excel 95/5.0 fil, använd LoadOptions och ställ in den relaterade attributen för LoadOptions-klassen för den mallfil som ska laddas. En provfil för att testa den här funktionen kan laddas ner från följande länk:
// 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!"); | |
} |
Öppna Microsoft Excel 97-2003 filer
För att öppna en Microsoft Excel 97 - 2003 fil, använd LoadOptions och ställ in den relaterade attributen för LoadOptions-klassen för den mallfil som ska laddas.
// 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!"); | |
} |
Öppna Microsoft Excel 2007/2010/2013/2016/2019 och Office 365 XLSX-filer
För att öppna en Microsoft Excel 2007/2010/2013/2016/2019 och Office 365-format, dvs. XLSX eller XLSB, ange filvägen. Du kan också använda LoadOptions och ställa in den relaterade attributen/alternativen för klassen LoadOptions som ska laddas.
// 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!"); |
Öppna krypterade Excel-filer
Det är möjligt att skapa krypterade Excel-filer med hjälp av 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 mönsterfilen som ska laddas. En testfil för att testa den här funktionen kan laddas ner från följande länk:
// 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 stöder också öppning av lösenordsskyddade Microsoft Excel 2007, 2010, 2013, 2016, 2019, Office 365 filer.