how to create,modify,append a excel file from asp.net using vb?
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-msoffice' list.


Andy Xa-Byte
Hi,

This is anand, can any body help me in this problem. I want to write a code which will create new xls file and inserts values into it. i want to use asp.net using vb codes . i have downloaded some codes which will help me in doing the same in asp.net using vc# code. but i want to use vb.

i tried this code

Dim xl As New Object()
Dim wb As Excel.Workbook
Dim sh As Excel.Worksheet
xl = CreateObject("excel.application")
wb = xl.Workbooks.Open("c:\sample2.xls")
sh = wb.Worksheets
sh.Cells(3, 4) = "its a sample page"
wb.Save()
wb.Close()
xl.Application.Quit()
Response.Write("complete")

but its not working.. when i execute i get a error as

"cannot create activex componenet " at
xl = createobject("excel.application")

in the description of the exception it tells me to reinstall the activex component. i installed Excel component in my system but even then it didnt work.

Please help me in doing this.

regards,
anand (andy)
Reply to this message...
 
    
Eduardo Barbosa
Greetings,

Try this sample code, i have it working in two applications. I usu it to
change data on a template excel file and then send it to the client.

Dim ObjExcel As New Excel.Application()
Dim ObjWS As Excel.Worksheet

Dim Report As ClsReport

' Thread in english so that excel com object don´t return error
System.Threading.Thread.CurrentThread.CurrentCulture System.Globalization.CultureInfo.CreateSpecificCulture("en-US")

ObjExcel.Visible = True

'Define o excel workbook
ObjExcel.Workbooks.Add()
ObjExcel.Workbooks.Open("filename.xls")
Dim ObjW = ObjExcel.ActiveWorkbook

ObjWS = ObjExcel.Worksheets("sheetName")

...
ObjWS.Cells(1, 1) = "Excel example"

...
ObjW.Save()

ObjExcel.Quit()
Marshal.ReleaseComObject(ObjW)
Marshal.ReleaseComObject(ObjExcel)

ObjExcel = Nothing
System.GC.Collect()
System.GC.Collect()
...

Best Regards

Eduardo Barbosa

------------------------------------------

Programar+

Analista Programador

http://www.evora.net/programar

Click here to reveal e-mail address

Tel. +351 266 730 187

Fax +351 266 730 186

------------------------------------------

-----Original Message-----
From: Trevor Pinkney [mailto:Click here to reveal e-mail address]
Sent: segunda-feira, 12 de Agosto de 2002 14:19
To: ngfx-msoffice
Subject: [ngfx-msoffice] RE: how to create,modify,append a excel file
from asp.net using vb?

Did you set a reference to it?

-----Original Message-----
From: Andy Xa-Byte [mailto:Click here to reveal e-mail address]
Sent: Saturday, August 10, 2002 4:55 AM
To: ngfx-msoffice
Subject: [ngfx-msoffice] how to create,modify,append a excel file from
asp.net using vb?

Hi,

This is anand, can any body help me in this problem. I want to write a
code which will create new xls file and inserts values into it. i want
to use asp.net using vb codes . i have downloaded some codes which will
help me in doing the same in asp.net using vc# code. but i want to use
vb.

i tried this code

Dim xl As New Object()

Dim wb As Excel.Workbook

Dim sh As Excel.Worksheet

xl = CreateObject("excel.application")

wb = xl.Workbooks.Open("c:\sample2.xls")

sh = wb.Worksheets

sh.Cells(3, 4) = "its a sample page"

wb.Save()

wb.Close()

xl.Application.Quit()

Response.Write("complete")

but its not working.. when i execute i get a error as

"cannot create activex componenet " at

xl = createobject("excel.application")

in the description of the exception it tells me to reinstall the activex
component. i installed Excel component in my system but even then it
didnt work.

Please help me in doing this.

regards,

anand (andy)

| [ngfx-msoffice] member Click here to reveal e-mail address = YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-msoffice.asp = JOIN/QUIT

| [ngfx-msoffice] member Click here to reveal e-mail address = YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-msoffice.asp = JOIN/QUIT
Reply to this message...
 
    
Scott Hutchinson
To access Excel from ASP.NET, you must grant the ASPNET user account launch permission for Excel in DCOM Config. To confirm that this is the problem, you could first test your code in a VB .NET Windows Form.

Also, for the best performance, IntelliSense, and early detection of bugs, use Dim ObjExcel As New Excel.Application()
(early binding) instead of CreateObject (late binding).

Also, change sh = wb.Worksheets to sh = wb.ActiveSheet or sh = wb.Worksheets(1) or best of all wb.Worksheets("worksheetname")

Scott Hutchinson
Click here to reveal e-mail address
(to contact me, remove all dots left of @)

"Andy Xa-Byte" <Click here to reveal e-mail address> wrote in message news:696243@ngfx-msoffice...
Hi,

This is anand, can any body help me in this problem. I want to write a code which will create new xls file and inserts values into it. i want to use asp.net using vb codes . i have downloaded some codes which will help me in doing the same in asp.net using vc# code. but i want to use vb.

i tried this code

Dim xl As New Object()
Dim wb As Excel.Workbook
Dim sh As Excel.Worksheet
xl = CreateObject("excel.application")
wb = xl.Workbooks.Open("c:\sample2.xls")
sh = wb.Worksheets
sh.Cells(3, 4) = "its a sample page"
wb.Save()
wb.Close()
xl.Application.Quit()
Response.Write("complete")

but its not working.. when i execute i get a error as

"cannot create activex componenet " at
xl = createobject("excel.application")

in the description of the exception it tells me to reinstall the activex component. i installed Excel component in my system but even then it didnt work.

Please help me in doing this.

regards,
anand (andy)
Reply to this message...
 
    
Andy
ya i did set the reference.. and i included the file in the code by using imports startement.
----- Original Message -----
From: Trevor Pinkney
To: ngfx-msoffice
Sent: Monday, August 12, 2002 6:49 PM
Subject: [ngfx-msoffice] RE: how to create,modify,append a excel file from asp.net using vb?

Did you set a reference to it?

-----Original Message-----
From: Andy Xa-Byte [mailto:Click here to reveal e-mail address]
Sent: Saturday, August 10, 2002 4:55 AM
To: ngfx-msoffice
Subject: [ngfx-msoffice] how to create,modify,append a excel file from asp.net using vb?

Hi,

This is anand, can any body help me in this problem. I want to write a code which will create new xls file and inserts values into it. i want to use asp.net using vb codes . i have downloaded some codes which will help me in doing the same in asp.net using vc# code. but i want to use vb.

i tried this code

Dim xl As New Object()

Dim wb As Excel.Workbook

Dim sh As Excel.Worksheet

xl = CreateObject("excel.application")

wb = xl.Workbooks.Open("c:\sample2.xls")

sh = wb.Worksheets

sh.Cells(3, 4) = "its a sample page"

wb.Save()

wb.Close()

xl.Application.Quit()

Response.Write("complete")

but its not working.. when i execute i get a error as

"cannot create activex componenet " at

xl = createobject("excel.application")

in the description of the exception it tells me to reinstall the activex component. i installed Excel component in my system but even then it didnt work.

Please help me in doing this.

regards,

anand (andy)

| [ngfx-msoffice] member Click here to reveal e-mail address = YOUR ID | http://www.aspfriends.com/aspfriends/ngfx-msoffice.asp = JOIN/QUIT

| [ngfx-msoffice] member Click here to reveal e-mail address = YOUR ID | http://www.aspfriends.com/aspfriends/ngfx-msoffice.asp = JOIN/QUIT
Reply to this message...
 
    
Eduardo Barbosa
Have you check if you are using version 10 ???
I want to use version 9 but VS automaticly selects version 10 instead.
If you cannot register manualy excel*.olb try to install office 97 or
2000.

The version 10 of the excel com object is reference as "excel.exe" not
an dll or a olb, and i had several problems with it.

Hope it helps
Eduardo Barbosa

------------------------------------------

Programar+

Analista Programador

http://www.evora.net/programar

Click here to reveal e-mail address

Tel. +351 266 730 187

Fax +351 266 730 186

------------------------------------------

-----Original Message-----
From: Andy [mailto:Click here to reveal e-mail address]
Sent: terça-feira, 21 de Maio de 2002 22:38
To: ngfx-msoffice
Subject: [ngfx-msoffice] RE: how to create,modify,append a excel file
from asp.net using vb?

ya i did set the reference.. and i included the file in the code by
using imports startement.

----- Original Message -----
From: Trevor <mailto:Click here to reveal e-mail address> Pinkney
To: ngfx-msoffice <mailto:Click here to reveal e-mail address>
Sent: Monday, August 12, 2002 6:49 PM
Subject: [ngfx-msoffice] RE: how to create,modify,append a excel file
from asp.net using vb?

Did you set a reference to it?

-----Original Message-----
From: Andy Xa-Byte [mailto:Click here to reveal e-mail address]
Sent: Saturday, August 10, 2002 4:55 AM
To: ngfx-msoffice
Subject: [ngfx-msoffice] how to create,modify,append a excel file from
asp.net using vb?

Hi,

This is anand, can any body help me in this problem. I want to write a
code which will create new xls file and inserts values into it. i want
to use asp.net using vb codes . i have downloaded some codes which will
help me in doing the same in asp.net using vc# code. but i want to use
vb.

i tried this code

Dim xl As New Object()

Dim wb As Excel.Workbook

Dim sh As Excel.Worksheet

xl = CreateObject("excel.application")

wb = xl.Workbooks.Open("c:\sample2.xls")

sh = wb.Worksheets

sh.Cells(3, 4) = "its a sample page"

wb.Save()

wb.Close()

xl.Application.Quit()

Response.Write("complete")

but its not working.. when i execute i get a error as

"cannot create activex componenet " at

xl = createobject("excel.application")

in the description of the exception it tells me to reinstall the activex
component. i installed Excel component in my system but even then it
didnt work.

Please help me in doing this.

regards,

anand (andy)

| [ngfx-msoffice] member Click here to reveal e-mail address = YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-msoffice.asp = JOIN/QUIT

| [ngfx-msoffice] member Click here to reveal e-mail address = YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-msoffice.asp = JOIN/QUIT

| [ngfx-msoffice] member Click here to reveal e-mail address = YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-msoffice.asp = JOIN/QUIT
Reply to this message...
 
 
System.GC
System.Globalization.CultureInfo
System.Runtime.InteropServices.Marshal
System.Threading.Thread




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com