Eliminar Filas y Columnas en Blanco en una Hoja de Cálculo
Contents
[
Hide
]
Es posible eliminar todas las filas y columnas en blanco de una hoja de cálculo. Esto es útil, por ejemplo, al generar un archivo PDF a partir de un archivo de Microsoft Excel y se desea convertir solo las filas y columnas que contienen datos u objetos relacionados.
Use los siguientes métodos de Aspose.Cells para eliminar filas y columnas vacías:
- Para eliminar filas en blanco, utilice el método Cells.DeleteBlankRows(). Tenga en cuenta que, para las filas en blanco que se eliminarán, no solo es necesario que Row.IsBlank sea verdadero, sino que también no debe haber comentarios visibles definidos para ninguna celda en esas filas, y no debe haber una tabla dinámica cuyo rango se interseque con ellas.
- Para eliminar columnas en blanco, utilice el método Cells.DeleteBlankColumns().
Código C# para eliminar filas en blanco
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"); |
Código C# para eliminar columnas en blanco
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"); |