C# EPPlus How to hide range of columns
-
I am working with EPPlus which generate excel file. now i have to hide range of columns. this code i used to hide range of columns in one go.
var rangecol = ws.Cells["M1:P1"];
var hiddenColumns = rangecol
.Select(cell => cell.Start.Column)
.Distinct()
.Select(rangecol.Worksheet.Column)
.ToList();foreach (var column in hiddenColumns)
{
column.Hidden = true;
}the above code is working and hiding columns but if there are 4 columns in range then it is hiding 4 columns individually not hide in one block. i want 4 columns should be hide in one block instead of 4 blocks. please tell me what mistake is there in my code for which groups of columns are not getting hidden in one block. Thanks
-
I am working with EPPlus which generate excel file. now i have to hide range of columns. this code i used to hide range of columns in one go.
var rangecol = ws.Cells["M1:P1"];
var hiddenColumns = rangecol
.Select(cell => cell.Start.Column)
.Distinct()
.Select(rangecol.Worksheet.Column)
.ToList();foreach (var column in hiddenColumns)
{
column.Hidden = true;
}the above code is working and hiding columns but if there are 4 columns in range then it is hiding 4 columns individually not hide in one block. i want 4 columns should be hide in one block instead of 4 blocks. please tell me what mistake is there in my code for which groups of columns are not getting hidden in one block. Thanks
What do you mean by "hidden in one block"? As far as I can see, at least in Microsoft Excel, there is no behavioural difference a sheet with four adjacent columns hidden one-by-one and a sheet where the four columns were selected and all four were hidden at the same time.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I am working with EPPlus which generate excel file. now i have to hide range of columns. this code i used to hide range of columns in one go.
var rangecol = ws.Cells["M1:P1"];
var hiddenColumns = rangecol
.Select(cell => cell.Start.Column)
.Distinct()
.Select(rangecol.Worksheet.Column)
.ToList();foreach (var column in hiddenColumns)
{
column.Hidden = true;
}the above code is working and hiding columns but if there are 4 columns in range then it is hiding 4 columns individually not hide in one block. i want 4 columns should be hide in one block instead of 4 blocks. please tell me what mistake is there in my code for which groups of columns are not getting hidden in one block. Thanks
In VBA it would be (for the columns from D to F):
Columns("D:F").Select Selection.EntireColumn.Hidden = True
Try to find something similar in C#