简体   繁体   中英

How to export specific columns from DataGridView to Excel or CSV in C#?

I am new to C# and trying to find some code to Export my DataGridView to an Excel or CSV file.

All the posts I can find online export the whole DataGridView and I only want 4 specific columns. Can anyone point me in the right direction please?

If it is possible I would also like to rename the column Headers in the CSV file.

Thanks in advance for any help.

The easy way is to filter out what you don't need and then pass that information to excel library. As for the header, just add an extra line at the beginning of the array your passing to excel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM