Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I made a datagridview for a project of mine, which is displayed as in the picture below :[^]

The columns on the left are generated from my database, while the ones on the right are added dynamically (they depend on a certain value).

Here is the code that I use to export it :

What I have tried:

The issue with it is that I don't get the dynamically added columns. The merging also doesn't work. Can anyone please help me? Thank you for your time !
Updated 6-Jul-23 0:49am

1 solution

Recommended method of doing work from C# was given here: Export datagridview to excel while keeping the formatting[^]:
1. Create a Macro recording of the actions that you wish to perform
2. View the VBA code generated for you
3. Use the VBA code to guide you for writing your C# code

If you follow these steps, and the original answer given, you will easily solve this question.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900