Radera tomma rader och kolumner i ett kalkylblad
Contents
[
Hide
]
Det är möjligt att ta bort alla tomma rader och kolumner från ett kalkylblad. Detta är användbart när man till exempel genererar en PDF-fil från en Microsoft Excel-fil och vill konvertera endast rader och kolumner som innehåller data eller relaterade objekt.
Använd följande Aspose.Cells-metoder för att ta bort tomma rader och kolumner:
- För att ta bort tomma rader, använd metoden Cells.delete_blank_rows(). Observera, för tomma rader som kommer att tas bort, krävs det inte bara att Row.is_blank ska vara sant, utan det får inte heller finnas någon synlig kommentar definierad för någon cell i dessa rader, och ingen pivottabell vars omfång korsar dem.
- För att ta bort tomma kolumner, använd metoden Cells.delete_blank_columns().
C# kod för att ta bort tomma rader
This file contains hidden or 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
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Open an existing excel file. | |
wb = Workbook(dataDir + "SampleInput.xlsx") | |
# Create a Worksheets object with reference to | |
# The sheets of the Workbook. | |
sheets = wb.worksheets | |
# Get first Worksheet from WorksheetCollection | |
sheet = sheets[0] | |
# Delete the Blank Rows from the worksheet | |
sheet.cells.delete_blank_rows() | |
# Save the excel file. | |
wb.save(dataDir + "mybook.out.xlsx") |
C# kod för att ta bort tomma kolumner
This file contains hidden or 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
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Open an existing excel file. | |
wb = Workbook(dataDir + "SampleInput.xlsx") | |
# Create a Worksheets object with reference to | |
# The sheets of the Workbook. | |
sheets = wb.worksheets | |
# Get first Worksheet from WorksheetCollection | |
sheet = sheets[0] | |
# Delete the Blank Columns from the worksheet | |
sheet.cells.delete_blank_columns() | |
# Save the excel file. | |
wb.save(dataDir + "mybook.out.xlsx") |