Удаление пустых строк и столбцов в листе
Contents
[
Hide
]
Можно удалить все пустые строки и столбцы из листа. Это полезно, например, при создании файла PDF из файла Microsoft Excel и требуется конвертировать только строки и столбцы, содержащие данные или связанные объекты.
Используйте следующие методы Aspose.Cells для удаления пустых строк и столбцов:
- Для удаления пустых строк используйте метод Cells.delete_blank_rows(). Обратите внимание, для удаляемых пустых строк требуется, чтобы Row.is_blank был равен true, а также не должно быть видимых комментариев для любой ячейки в этих строках, и не должно быть сводной таблицы, диапазон которой пересекается с ними.
- Чтобы удалить пустые столбцы, используйте метод Cells.delete_blank_columns().
C# код для удаления пустых строк
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# код для удаления пустых столбцов
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") |