create an Excel sheet in vb.net

Signo.X

Well-known member
Joined
Aug 21, 2006
Messages
76
Location
Australia
Programming Experience
1-3
Hello all,

a quick question , whats a simple code to create/replace a basic excel work sheet using vb.net..

thats what i have so far ..
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] xa [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Application[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] xwb [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Workbook[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] xws [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Worksheet[/SIZE]
[SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[SIZE=2]xwb = xa.Workbooks.Open([/SIZE][SIZE=2][COLOR=#800000]"C:\test.xsl"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]xwb.Activate()[/SIZE]

but thats only open the file in the background and doesnt display it , i cant find any code that will "create" an excel document and then open it to the user...???

Thanks in Advance!!

~Signo.X
 
xa.Visible = True

Should give the ability to show the spreadsheet you have just created. I would question what you are doing though. Are you just trying to open that sheet to the user and then you are done? If your creating instances of the Application and Worksheet/Books your going to have to manage those to ensure they leave memory.

If all you want to do it open an XLS sheet for the user I would suggest useing Process instead to fire off Excel w/ the XLS name as an arguement.
 
Thanks for your replay Raven ,

Problem Solved !!

based on my windows form , the user would select the orders he wants, then i want to get the total orders from the DB through a query , and based on the returned values i wanted to construct a report using excel...

the problem was i wanted to overwrite the existing .xsl file (if any exist) in the directory, so every time the user has the most updated report based on his required info...

so what i did to solve the excel part is check if the file exist, other wise just create on and etc..


!signo.X
 
Last edited:
Back
Top