Ouverture de différents fichiers de versions Excel Microsoft
Ouverture de fichiers de différentes versions d’Excel Microsoft
Une application doit souvent pouvoir ouvrir des fichiers Excel Microsoft 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 nombreux formats, y compris XLS, XLSX, XLSM, XLSB, SpreadsheetML, TabDelimited ou TSV, CSV, ODS et ainsi de suite. Utilisez le constructeur ou utilisez le**Classeur** classe'**setFileFormat**méthode pour spécifier le format à l’aide de la**FileFormatType**énumération.
Le**FileFormatType**énumération contient de nombreux formats de fichiers prédéfinis dont certains sont donnés ci-dessous.
Types de formats de fichiers | Description |
---|---|
CSV | Représente un fichier CSV |
EXCELLER_97_À_2003 | Représente un fichier Excel 97 - 2003 |
XLSX | Représente un fichier Excel 2007/2010/2013/2016/2019 et Office 365 XLSX |
XLSM | Représente un fichier Excel 2007/2010/2013/2016/2019 et Office 365 XLSM |
XLTX | Représente un fichier de modèle Excel 2007/2010/2013/2016/2019 et Office 365 XLTX |
XLTM | Représente un fichier Excel 2007/2010/2013/2016/2019 et Office 365 prenant en charge les macros XLTM |
XLSB | Représente un fichier Excel 2007/2010/2013/2016/2019 et Office 365 binaire XLSB |
SPREADSHEET_ML | Représente un fichier SpreadsheetML |
TSV | Représente un fichier de valeurs séparées par des tabulations |
ONGLET DÉLIMITÉ | Représente un fichier texte délimité par des tabulations |
ODS | Représente un fichier ODS |
HTML | Représente un fichier HTML |
M_HTML | Représente un fichier MHTML |
Ouverture des fichiers Microsoft Excel 95/5.0
Pour ouvrir un fichier Microsoft Excel 95/5.0, utilisez**LoadOptions**et définissez l’attribut associé pour le**ChargerOptions**class pour le fichier modèle à charger. Un exemple de fichier pour tester cette fonctionnalité peut être téléchargé à partir du lien suivant :
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!"); |
Ouverture des fichiers Microsoft Excel 97 - 2003
Pour ouvrir un fichier Microsoft Excel 97 - 2003, utilisez**LoadOptions** et définissez l’attribut associé pour le**ChargerOptions**class pour le fichier modèle à charger.
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!"); |
Ouverture Microsoft Fichiers Excel 2007/2010/2013/2016/2019 et Office 365 XLSX
Pour ouvrir un format Microsoft Excel 2007/2010/2013/2016/2019 et Office 365, c’est-à-dire XLSX ou XLSB, indiquez le chemin du fichier. Vous pouvez aussi utiliser**LoadOptions** et définissez les attributs/options associés du**ChargerOptions**class pour le fichier modèle à charger.
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!"); |
Ouverture de fichiers Excel cryptés
Il est possible de créer des fichiers Excel cryptés en utilisant Microsoft Excel. Pour ouvrir un fichier crypté, utilisez le**LoadOptions** et définir ses attributs et options (par exemple, donner un mot de passe) pour le fichier modèle à charger. Un exemple de fichier pour tester cette fonctionnalité peut être téléchargé à partir du lien suivant :
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 prend également en charge l’ouverture de fichiers Microsoft Excel 2007, 2010, 2013, 2016, 2019, Office 365 protégés par mot de passe.