Yes, it's possible, with certain degree of approximation, and even pretty good. I have no idea why doing so, but to work with Excel, you will need to use Microsoft Office Interop assembly. If Excel is installed, you have appropriate assembly "Microsoft.Office.Interop.Excel" of appropriate version on GAC, so you can add it from the tab ".NET" of the "Add Reference" window.
Please see:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel%28v=office.14%29.aspx[
^].
(Use the documentation of the version you want to use.)
As assume the code with
DataGridView
is yours, so you should know where did you define all column/cell styles to read them and create similar Excel styles.
Many ask if it's possible without Office installation, which is actual for deployment to arbitrary users, as you may or may not allow yourself demand that the users had appropriate Office installation as a prerequisite for using your product. I provided my answers here:
Convert Office-Documents to PDF without interop[
^],
Hi how can i display word file in windows application using c#.net[
^],
Read a word file without using Interop.word dll...Do not want to install word in IIS..[
^].
Now, how about some not very pleasant note? All this is labor-taking and ineffective. I personally think that using such a proprietary product as Microsoft Office is a bad thing for a software team or a company, leading to
vendor lock-in (
http://en.wikipedia.org/wiki/Vendor_lock-in[
^]). The desire to export things to Office reflect non a software developer point of view, but the views of a inexperienced user thinking that Office is a major part of computer functionality, due to very limited knowledge and experience. You might easier provide everything what the user wants using pure .NET and nothing else, without unwanted investments. However, I understand that I don't know anything about your product, so you should know better what you really need.
—SA