Supprimer les lignes et colonnes vides dans une feuille de calcul
Il est possible de supprimer toutes les lignes et colonnes vides d’une feuille de calcul. Cela est utile, par exemple, lors de la génération d’un fichier PDF à partir d’un fichier Microsoft Excel et que vous souhaitez convertir uniquement les lignes et les colonnes contenant des données.
Utilisez les méthodes Aspose.Cells suivantes pour supprimer les lignes et colonnes vides :
- Pour supprimer les lignes vides, utilisez la méthode Cells.deleteBlankRows().
- Pour supprimer les colonnes vides, utilisez la méthode Cells.deleteBlankColumns().
Suppression des lignes vides
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(DeletingBlankRows.class); | |
// Create a new Workbook. Open an existing excel file. | |
Workbook wb = new Workbook(dataDir + "Book1.xlsx"); | |
// Create a Worksheets object with reference to the sheets of the Workbook. | |
WorksheetCollection sheets = wb.getWorksheets(); | |
// Get first Worksheet from WorksheetCollection | |
Worksheet sheet = sheets.get(0); | |
// Delete the Blank Rows from the worksheet | |
sheet.getCells().deleteBlankRows(); | |
// Save the excel file. | |
wb.save(dataDir + "Output.xlsx"); | |
Suppression des colonnes vides
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(DeletingBlankColumns.class); | |
// Create a new Workbook. Open an existing excel file. | |
Workbook wb = new Workbook(dataDir + "Book1.xlsx"); | |
// Create a Worksheets object with reference to the sheets of the Workbook. | |
WorksheetCollection sheets = wb.getWorksheets(); | |
// Get first Worksheet from WorksheetCollection | |
Worksheet sheet = sheets.get(0); | |
// Delete the Blank Columns from the worksheet | |
sheet.getCells().deleteBlankColumns(); | |
// Save the excel file. | |
wb.save(dataDir + "Output.xlsx"); |