Click here to Skip to main content
15,798,066 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone

I have a gridview with a custom style and row colors and i want a stable method to export this grid data to excel file with the same format.

Thanks in advance :)
Updated 12-Jun-13 8:56am

You're going to have to either use the Excel object model or the OpenOffice SDK, depending on the version of Excel you're talking about. The Excel object model is not known for it's speed and the OpenOfficeSDK has a bit of a steep learning curve to use.

In either case, you'll be creating the workbook, worksheet, putting the individual cell values from the DGV into appropriate cells in the worksheet, and, finally, using the various methods for format the ranges of cells you need. You'll be pretty much following the steps you would in Excel if you were to format and color the cells by hand in Excel.

No, there is no automated way to do this to save you from writing a ton of code.
Share this answer
If you don't want to use any Excel classes,
You can make your own XML file and save as XLS.
Share this answer
Dave Kreskowiak 12-Jun-13 16:37pm    
That's what the OpenOfficeSDK is for.
Tom Wauters 12-Jun-13 16:45pm    
My bad.

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