Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide a large number of columns in an excel spreadsheet using EPPlus?

Tags:

c#

excel

epplus

I am using EPPlus version 3.1.3 to create a spreadsheet and I want to hide all of the columns from column L to column XFD and all the rows from the bottom most row to the end. I'm trying to hide the columns by using:

for (int i = 12; i <= 16384; i++)
{
     worksheet.Column(i).Hidden = true; 
}

This takes forever though for this loop to run. Does anyone know of an alternative way to hide a large amount of columns? I also have no idea how to hide the rows.

I'm wondering if there is another solution outside of EPPlus, but I really don't want to add another library to this.

like image 589
Adam Avatar asked Aug 22 '14 17:08

Adam


People also ask

How do I hide columns in Excel Epplus?

Apparently according to the documentation, you can use AutoFitColumns(Double MinimumWidth, Double MaximumWidth) : Set the column width from the content of the range. Note: Cells containing formulas are ignored if no calculation is made. Wrapped and merged cells are also ignored.

How do I mass hide a column in Excel?

Hide columns Select one or more columns, and then press Ctrl to select additional columns that aren't adjacent. Right-click the selected columns, and then select Hide.

How do you hide rows or columns with an easily visible expand?

Grouping Rows or ColumnsGroups and outlines allow you to quickly hide and unhide rows or columns in an Excel spreadsheet. The Groups feature creates row and column groupings in the Headings section of the worksheet. Each group can be expanded or collapsed with the click of a button.


1 Answers

I've found a solution for the columns.

I wanted to hide columns 10 to 16384 (last). The following Code did the trick and has a good performance.

//EPPlus 4.04 is used.

Dim col As ExcelColumn = osheet.Column(10)
col.ColumnMax = 16384
col.Hidden = True
like image 128
Tobi Avatar answered Nov 15 '22 06:11

Tobi