Ouvrir des fichiers de différentes versions de Microsoft Excel
Comment ouvrir des fichiers de différentes versions de Microsoft Excel
Une application doit souvent être capable d’ouvrir des fichiers Microsoft Excel créés dans différentes versions, par exemple, Microsoft Excel 95, 97, ou Microsoft Excel 2007/2010/2013/2016/2019 et Office 365. Vous devrez peut-être charger un fichier dans l’un des plusieurs formats, y compris XLS, XLSX, XLSM, XLSB, SpreadsheetML, TabDelimited ou TSV, CSV, ODS, etc. Utilisez le constructeur, ou spécifiez l’attribut de type FileFormat de la classe Workbook qui spécifie le format en utilisant l’énumération FileFormatType.
L’énumération FileFormatType contient de nombreux formats de fichier prédéfinis dont certains sont donnés ci-dessous.
Types de formats de fichier | Description |
---|---|
Csv | Représente un fichier CSV |
Excel97To2003 | Représente un fichier Excel 97 - 2003 |
Xlsx | Représente un fichier XLSX Excel 2007/2010/2013/2016/2019 et Office 365 |
Xlsm | Représente un fichier XLSM Excel 2007/2010/2013/2016/2019 et Office 365 |
Xltx | Représente un modèle de fichier XLTX Excel 2007/2010/2013/2016/2019 et Office 365 |
Xltm | Représente un fichier activé par macro XLTM Excel 2007/2010/2013/2016/2019 et Office 365 |
Xlsb | Représente un fichier binaire XLSB Excel 2007/2010/2013/2016/2019 et Office 365 |
SpreadsheetML | Représente un fichier SpreadsheetML |
Tsv | Représente un fichier de valeurs séparées par des tabulations |
TabDelimited | Représente un fichier de texte à onglets |
Ods | Représente un fichier ODS |
Html | Représente un fichier HTML |
Mhtml | Représente un fichier MHTML |
Ouvrir les fichiers Microsoft Excel 95/5.0
Pour ouvrir un fichier Microsoft Excel 95/5.0, utilisez LoadOptions et définissez l’attribut associé pour la classe LoadOptions du fichier modèle à charger. Un fichier d’exemple pour tester cette fonctionnalité peut être téléchargé à partir du lien suivant:
// 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!"); | |
} |
Ouvrir les fichiers Microsoft Excel 97-2003
Pour ouvrir un fichier Microsoft Excel 97 - 2003, utilisez LoadOptions et définissez l’attribut associé pour la classe LoadOptions du fichier modèle à charger.
// 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!"); | |
} |
Ouvrir les fichiers XLSX de Microsoft Excel 2007/2010/2013/2016/2019 et Office 365
Pour ouvrir un fichier au format Microsoft Excel 2007/2010/2013/2016/2019 et Office 365, c’est-à-dire XLSX ou XLSB, spécifiez le chemin d’accès au fichier. Vous pouvez également utiliser LoadOptions et définir les attributs/options associées de la classe LoadOptions pour le fichier modèle à charger.
// 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!"); |
Ouvrir des fichiers Excel chiffrés
Il est possible de créer des fichiers Excel chiffrés à l’aide de Microsoft Excel. Pour ouvrir un fichier chiffré, utilisez LoadOptions et définissez ses attributs et options (par exemple, donnez un mot de passe) pour le fichier modèle à charger. Un fichier d’exemple pour tester cette fonctionnalité peut être téléchargé à partir du lien suivant:
// 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 prend également en charge l’ouverture de fichiers Microsoft Excel 2007, 2010, 2013, 2016, 2019, Office 365 protégés par mot de passe.