I'm trying to export the contents of a datagrid to excel which I have been able to do as long as its to a generic excel workbook. I can't figure out how to direct to open a specific workbook, create a new tab with a name that I create in code, & save the datagrid to that. tab(worksheet).

For example I want it to open C:\mydocuments\myworkbook.xls, create a new worksheet named "0914 to 0920", and export the datgrid to that.

I've been able to designate a file name but no luck with path or worksheet names

Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=" & myfilename)
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
GridView2.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()

This is an old post but I thought I would bump it as I am having the same issue.

The file to open to post result to a excel tab could be stored on the server in my case though. If that makes it any easier.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.