Trim spreadsheet

1 Answer 91 Views
SpreadProcessing
Stas
Top achievements
Rank 1
Stas asked on 15 Aug 2024, 12:12 AM

I see Sreadsheet processing has row removal feature but it seems you need to know the range of rows you want to remove. 

How would you recommend acheiving something like a trim functionality? Excel spreadsheets in my experience are notorious for having potenatially pages and pages of empty rows after all the actual content.  In fact I am working with one like that now.How can I get rid of those empty rows?

 

Thank you!

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 19 Aug 2024, 12:47 PM

Hello Stas,

To achieve the described results you can use the Hidden Rows and Columns functionality of the SpreadProcessing library.

Example:

Workbook workbook;
IWorkbookFormatProvider xlsxFormatProvider = new XlsxFormatProvider();

using (Stream input = new FileStream("input.xlsx", FileMode.Open))
{
    workbook = xlsxFormatProvider.Import(input);
}

Worksheet worksheet = workbook.ActiveWorksheet;
var allRowsCount = worksheet.Rows.Count;

var rowIndexOfLastRowOfUsedCellRange = worksheet.UsedCellRange.GetLastRow().ToIndex.RowIndex;

RowSelection rowSelection = worksheet.Rows[rowIndexOfLastRowOfUsedCellRange + 1, allRowsCount - 1];
rowSelection.SetHidden(true);

I am attaching a sample project that implements this functionality for your disposal.

Note: If you are by any chance using the UI for Blazor Spreadsheet control you can use its ExportToExcelAsync method to obtain the cell content as a byte array and import it for processing with SpreadProcessing's XlsxFormatProvider.

I hope this helps.

Regards,
Yoan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
SpreadProcessing
Asked by
Stas
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or