Articles in this section

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

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 the 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()

The screenshot below shows that 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: Exporting

 

Conclusion

I hope you enjoyed learning how to hide certain columns and lock or unlock columns while exporting WinForms GridGroupingControl to Excel.

You can refer to our WinForms GridGroupingControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to present and manipulate data.
 

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms GridGroupingControl and other WinForms components.

 

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied