 |
|
|
I am new in VB.NET. I have getting problem in these lines.
Dim excel As New Microsoft.Office.Interop.Excel.ApplicationClass Dim wBook As Microsoft.Office.Interop.Excel.Workbook Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet
telling me type 'Dim excel As New Microsoft.Office.Interop.Excel.ApplicationClass' is not defined
type 'Dim wBook As Microsoft.Office.Interop.Excel.Workbook ' is not defined.
type 'Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet ' is not defined
Pls help me
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Senthil
I am trying to use your code by just replacing datagrid with gridview properties...but only gridview header comes in excel..other all rows come as System.Web.UI.WebControls.DataControlFieldCell...also can you also show me how to set coloumn width and other such formating for my excel sheet..plz reply soon..its givin me sleepless nights my code for the same at button clicj event is If ((grdPharmacy.Columns.Count = 0) Or (grdPharmacy.Rows.Count = 0)) Then Exit Sub End If
'Creating dataset to export Dim dset As New DataSet 'add table to dataset dset.Tables.Add() 'add column to that table For i As Integer = 0 To grdPharmacy.Columns.Count - 1 dset.Tables(0).Columns.Add(grdPharmacy.Columns(i).HeaderText) Next 'add rows to the table Dim dr1 As DataRow For i As Integer = 0 To grdPharmacy.Rows.Count - 1 dr1 = dset.Tables(0).NewRow For j As Integer = 0 To grdPharmacy.Columns.Count - 1 dr1(j) = grdPharmacy.Rows(i).Cells(j) Next dset.Tables(0).Rows.Add(dr1) Next
Dim excel As New Microsoft.Office.Interop.Excel.ApplicationClass Dim wBook As Microsoft.Office.Interop.Excel.Workbook Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet
wBook = excel.Workbooks.Add() wSheet = wBook.ActiveSheet()
Dim dt As System.Data.DataTable = dset.Tables(0) Dim dc As System.Data.DataColumn Dim dr As System.Data.DataRow Dim colIndex As Integer = 0 Dim rowIndex As Integer = 0
For Each dc In dt.Columns colIndex = colIndex + 1 excel.Cells(1, colIndex) = dc.ColumnName Next
For Each dr In dt.Rows rowIndex = rowIndex + 1 colIndex = 0 For Each dc In dt.Columns colIndex = colIndex + 1 excel.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
Next Next
wSheet.Columns.AutoFit() Dim strFileName As String = "C:\Book2.xls" Dim blnFileOpen As Boolean = False Try Dim fileTemp As System.IO.FileStream = System.IO.File.OpenWrite(strFileName) fileTemp.Close() Catch ex As Exception blnFileOpen = False End Try
If System.IO.File.Exists(strFileName) Then System.IO.File.Delete(strFileName) End If
wBook.SaveAs(strFileName) excel.Workbooks.Open(strFileName) excel.Visible = True
thanks in advance
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, I am developing .Net project using vb.net language. My question is i want to create update excel file thru' vb.net coding. When i am running application in asp server. My excel file is updating. But when i am trying to run the same application from other computer i can't. No error. But not resukt also. My code is as follows
FileUpload1.SaveAs(Server.MapPath("~\reports\") & FileUpload1.FileName) ' open a saved excel file Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet
xlApp = New Excel.ApplicationClass xlWorkBook = xlApp.Workbooks.Open(Server.MapPath("~\reports\") & FileUpload1.FileName) xlWorkSheet = xlWorkBook.Sheets(1) xlWorkSheet.Cells(1, 2) = "Tesing Excel"
xlWorkBook.Save() ReleaseComObject(xlApp) ReleaseComObject(xlWorkBook) ReleaseComObject(xlWorkSheet)
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hi Senthil S , How are you , i just want to know that why do you include the following lines in your code because after removing those lines code is still working.
Dim blnFileOpen As Boolean = False Try Dim fileTemp As System.IO.FileStream = System.IO.File.OpenWrite(strFileName) fileTemp.Close() Catch ex As Exception blnFileOpen = False End Try
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Blue Stone, Fine, thanks, How about you?
The code is for close the excel file. That is the above code will create and open the excel sheet. And i am use these codes to closing the excel sheet for multi excel files creation.
Senthil.S A Software Engineer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Senthil its working fine in my system, but when i try to run this application to another system its not working.. once i imports microsoft.office.11.0 object library and Excel only this application run...
So should we imports this COM Object for each and every system?
I would like beat this error... Please help me...
Thanks and Regards J.Kasim Mohamed
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hello Mohamed
I tried over come this issue. But my code directly required the MS Office components to create and transfer the details in the envio. of MS Office itself. So the code needs MS Office components.
Their is also other way that will transfer and create excel files without openings or accessing the MS Environment.
Senthil.S A Software Engineer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Sir, I had used your code and it's good. I were able to export a SQL Database to Microsoft Excel. Thanks a lot sir.
I'm here to seek help from you. Is it possible to just OPEN the excel file and just replace a particular sheet (ex: Sheet 1)inside the excel file?...Thanks in advance sir!..
Regards,
jeffrey
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
I have two excel work book and I have to remove data from one book another book, all I have to do is get the data from 1st book(table) and remove that existing data in the 2nd book(table),I know how to write SQL code using SELECT * all that , but I have to use this excel workbook and using MS ACCESS platform and SQL coding,
please help me out
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
u'r work really nice i too hav similar task but instead of storing it in the database i hav to directly export datas to excel after entering
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Microsoft.Office.Interop.Excel.ApplicationClass not defined even though it is defined.imilsr two errors are in the program.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Microsoft.Office.Interop.Excel.ApplicationClass Microsoft.Office.Interop.Excel.Workbook Microsoft.Office.Interop.Excel.Worksheet are not defined i had declared Imports Microsoft.Office.Interop.Excel.ApplicationClass at the top still error could you help me?
modified on Saturday, September 13, 2008 11:58 PM
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
hi senthil:
i have a datagridview which needs to be transferred to an excel spreadsheet. I use VS 2005 and ms access 2003(db) and excel 2003. I dont get any errors but i dont see the excel created;.. i also have another qn.. i have a few results colored in my datagridview.. how do i make it colored even in my excel spreadsheet ??
I would really appreciate ur help..Expecting a reply at the earliest.. I am sorry but I have been stuck on this for 2 weeks now..!
Thanks Senthil
Kavitha.
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If ((DataGridView1.Columns.Count = 0) Or (DataGridView1.Rows.Count = 0)) Then
Exit Sub
End If
Dim dset As New DataSet
dset.Tables.Add()
For i As Integer = 0 To DataGridView1.ColumnCount - 1
dset.Tables(0).Columns.Add(DataGridView1.Columns(i).HeaderText)
Next
Dim dr1 As DataRow
For i As Integer = 0 To DataGridView1.RowCount - 1
dr1 = dset.Tables(0).NewRow
For j As Integer = 0 To DataGridView1.Columns.Count - 1
dr1(j) = DataGridView1.Rows(i).Cells(j).Value
Next
dset.Tables(0).Rows.Add(dr1)
Next
Dim excel As New Microsoft.Office.Interop.Excel.Application
Dim wbook As Microsoft.Office.Interop.Excel.Workbook
Dim wsheet As Microsoft.Office.Interop.Excel.Worksheet
wbook = excel.Workbooks.Add()
wsheet = wbook.ActiveSheet()
Dim dt As System.Data.DataTable = dset.Tables(0)
Dim dc As System.Data.DataColumn
Dim dr As System.Data.DataRow
Dim colindex As Integer = 0
Dim rowindex As Integer = 0
For Each dc In dt.Columns
colindex = colindex + 1
excel.Cells(1, colindex) = dc.ColumnName
Next
For Each dr In dt.Rows
rowindex = rowindex + 1
colindex = 0
For Each dc In dt.Columns
colindex = colindex + 1
excel.Cells(rowindex + 1, colindex) = dr(dc.ColumnName)
Next
Next
wsheet.Columns.AutoFit()
Dim strfilename As String = "C:\Documents and Settings\bashkark\Desktop\MCAD.xls"
Dim blnfileopen As Boolean = False
Try
Dim filetemp As System.IO.FileStream = System.IO.File.OpenWrite(strfilename)
filetemp.Close()
Catch ex As Exception
blnfileopen = False
End Try
wbook.SaveAs(strfilename)
excel.Workbooks.Open(strfilename)
excel.Visible = True
MsgBox("created")
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 'This button is for navigating from Form3 to Form2
Dim formtoshow As New Form2
formtoshow.Show()
Me.Dispose()
End Sub
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Hello!
I am a just learning VB.Net. I have one problem with Exports data to excel that the 'Microsoft.Office.Interop.Excel' is not available. I am using Visual Studio Professional Edition 2005.
Kindly suggest.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hi, Sorry for late response.
To resolve this problem you need to install the MS Office fully. for that use the MS Office setup and start installing. if the system having ms office it will ask to update/remove. Use Update option with all package which is enabled by checking the checkbox present on the type of install ie on Select install type view(may be like that) Full/Default install. Here check the checkbox down and next screen select all the package and sub package(it must to select sub package indutually).
After that in our coding use referecne to import ms office liberary higher version. And add the import statment as i mentioned in article.
I think these solution help to resolve your question. Any doubt i will respond ASAP.
Thanks
Regards
Senthil.S Software Engineer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Dear Senthil,
First thing first thanks for the code and the help. Now I tried the code to generate from dataset to excel in an application that I personally built. (using access) Now the problem is it worked ok if they are few records in the database but when I actually used the real database which has over 600 records I got an exception which i logged saying Exception from HRESULT: 0x800A03EC. Source: " Record: at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateSet(Object o, Type& objType, String name, Object [] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType)
Will appreciate your help.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Dear Senthil S,
i hit an error when the line execute until wBook = excel.Workbooks.Add() "error Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))"
may i know how to solve this?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, Sorry for late response.
To resolve this problem you need to install the MS Office fully. for that use the MS Office setup and start installing. if the system having ms office it will ask to update/remove. Use Update option with all package which is enabled by checking the checkbox present on the type of install ie on Select install type view(may be like that) Full/Default install. Here check the checkbox down and next screen select all the package and sub package(it must to select sub package indutually).
After that in our coding use referecne to import ms office liberary higher version. And add the import statment as i mentioned in article.
I think these solution help to resolve your question. Any doubt i will respond ASAP.
Thanks
Regards
Senthil.S Software Engineer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Mr. Senthil,
I saw u r vb.net code for ExportToExcle code. The idea behind is very brillant. I using this conceptin my project. But i am facing the problem while running in Excel import. I already replace the refernces in vb.net with higher one. but its still not resolved. Pls help me out in this.
Thanikng You, nikhil
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
hi,
sorry for the inconvinence
Can you tell me what error now you getting?
Thanks
Senthil.S A Software Engineer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I tried your code for sending a datagrid to excel. I am using vb.net 2005 std. and I get the following error for each line of code:
Dim excel As New Microsoft.Office.Interop.Excel.ApplicationClass Dim wBook As Microsoft.Office.Interop.Excel.Workbook Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet
ERROR: "Type 'Microsoft.Office.Interop.Excel.ApplicationClass' is not defined"
What do I need to do to resolve this exception error?
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
add microsoft excel object reference then on top of your class Imports Microsoft.Office.Interop.Excel.ApplicationClass
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks. I found the references and added them. My problem is I added Microsoft Office 11.0 Excel Object Library. I have Office 2003 and 2007 loaded on my computer. I will not run on machines that do not have Office 2007. Is there anyway to get it to work on machines running Office 2003?
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
Add and Import the reference "Microsoft.Office.Interop". It is not available reinstall the MS Office with all the office tools. This will automatically create the reference.
Senthil.S Software Engineer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |