Eliminare Righe e Colonne Vuote in un Foglio di Lavoro
Contents
[
Hide
]
È possibile eliminare tutte le righe e le colonne vuote da un foglio di lavoro. Questo è utile, ad esempio, quando si genera un file PDF da un file Microsoft Excel e si desidera convertire solo le righe e le colonne che contengono dati o oggetti correlati.
Utilizzare i seguenti metodi Aspose.Cells per eliminare le righe e le colonne vuote:
- Per eliminare le righe vuote, utilizzare il metodo Cells.DeleteBlankRows(). Si prega di notare che, per le righe vuote che verranno eliminate, non è solo richiesto che Row.IsBlank sia vero, ma non deve essere definito alcun commento visibile per qualsiasi cella in quelle righe e non deve esserci alcuna tabella pivot il cui intervallo si sovrapponga con esse.
- Per eliminare le colonne vuote, utilizzare il metodo Cells.DeleteBlankColumns().
Codice C# per eliminare le righe vuote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// Open an existing excel file. | |
Workbook wb = new Workbook(dataDir+ "SampleInput.xlsx"); | |
// Create a Worksheets object with reference to | |
// The sheets of the Workbook. | |
WorksheetCollection sheets = wb.Worksheets; | |
// Get first Worksheet from WorksheetCollection | |
Worksheet sheet = sheets[0]; | |
// Delete the Blank Rows from the worksheet | |
sheet.Cells.DeleteBlankRows(); | |
// Save the excel file. | |
wb.Save(dataDir+ "mybook.out.xlsx"); |
Codice C# per eliminare le colonne vuote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// Open an existing excel file. | |
Workbook wb = new Workbook(dataDir+ "SampleInput.xlsx"); | |
// Create a Worksheets object with reference to | |
// The sheets of the Workbook. | |
WorksheetCollection sheets = wb.Worksheets; | |
// Get first Worksheet from WorksheetCollection | |
Worksheet sheet = sheets[0]; | |
// Delete the Blank Columns from the worksheet | |
sheet.Cells.DeleteBlankColumns(); | |
// Save the excel file. | |
wb.Save(dataDir+ "mybook.out.xlsx"); |