)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to hide certain columns and lock or unlock columns while exporting WinForms GridGroupingControl to Excel?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: April 15, 2016 |
Last Revised Date: February 12, 2020

Exporting

In order to hide some specific columns and also to lock or unlock columns while exporting from GridGroupingControl to Excel, the ShowColumn() method and the Locked property of worksheet can be used respectively.

C#

ExcelEngine engine = new ExcelEngine();
IApplication app = engine.Excel.Application;
app.DefaultVersion = ExcelVersion.Excel2010;
IWorkbook book = app.Workbooks.Create();
IWorksheet sheet = book.Worksheets[0];
excelConverter.GroupingGridToExcel(this.gridGroupingControl1, sheet, ConverterOptions.Default);
// Hides the Column index "2".
sheet.ShowColumn(2, false);
// Locks the cell range B12
sheet.Range["B12"].CellStyle.Locked = true;
// Unlocks the cell range A2
sheet.Range["A2"].CellStyle.Locked = false;
book.SaveAs(this.saveFileDialog1.FileName);
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = this.saveFileDialog1.FileName;
proc.Start();

VB

Dim engine As New ExcelEngine()
Dim app As IApplication = engine.Excel.Application
app.DefaultVersion = ExcelVersion.Excel2010
Dim book As IWorkbook = app.Workbooks.Create()
Dim sheet As IWorksheet = book.Worksheets(0)
excelConverter.GroupingGridToExcel(Me.gridGroupingControl1, sheet, ConverterOptions.Default)
' Hides the Column index "2".
sheet.ShowColumn(2, False)
' Locks the cell range B12
sheet.Range("B12").CellStyle.Locked = True
' Unlocks the cell range A2
sheet.Range("A2").CellStyle.Locked = False
book.SaveAs(Me.saveFileDialog1.FileName)
Dim proc As New System.Diagnostics.Process()
proc.StartInfo.FileName = Me.saveFileDialog1.FileName
proc.Start()

Screenshot

The below screen shot shows the column “Description” is hidden.

Show or hide the columns in excel

Show the values in excel

Samples:

C#: Excel Export_CS

VB: Excel Export_VB

Reference link: https://help.syncfusion.com/windowsforms/gridgrouping/exporting

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon