473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Read/Extract Excel Data in .NET

I am opening, reading and extracting an Excel spreadsheet in .Net (VB). It seems to work fine, however, when I am finished and I open up Excel and try to open up the file a message pops up "File Now Available", "select Read-Write or Cancel". Its almost like my code is changing the documents attributes. Am I doing something wrong in my code

Any help would be great. Thanks
Diann
PS: I'm not quite sure why, but it seems that I have to use the COM reference for Excel... Is there a .Net reference

Private Sub StartReadingDataFile(ByVal FileName As String
Dim strConn As String = "
Dim strSql As String = "
Dim dsExcel As New DataSet(
Dim xlWb As Excel.Workbook(
Dim xlApp As Excel.Applicatio
xlApp = New Excel.Application(
Dim xlWs As New Excel.Worksheet(
Dim [readOnly] As Object = Fals
Dim i As Intege
Dim ExcelData As New System.Data.OleDb.OleDbDataAdapter(strSql, strConn

'Create Output Data Schem
CreateOutTables(

'Set Up String Command With File Name (data source
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source=" & FileName & ";" &
"Extended Properties=""Excel 8.0;IMEX=1;""

'Loop Through each Tab and find tabs which begin with numeric characte
'Build SQ
'You must use the $ after the object you reference in the spreadshee

For Each xlWs In xlApp.Workbooks.Open(FileName, [readOnly]).Worksheet
dsExcel = New DataSet(
strSql = "SELECT * FROM [" & xlWs.Name.ToString & "$]
ExcelData.SelectCommand.CommandText = strSq
ExcelData.SelectCommand.Connection.ConnectionStrin g = strCon
ExcelData.Fill(dsExcel, "Excel"
WriteDataSet(dsExcel
End I
Next xlW

'Free the Object
xlApp.Quit(
xlWb = Nothin
xlWs = Nothin
xlApp = Nothin

MsgBox("Data Processed, Verification Report to Proceed"

End Sub
Nov 22 '05 #1
1 1727
Hi

I could reproduce the same error with the code you have sent. Have done little changes

'Loop Through each Tab and find tabs which begin with numeric characte
'Build SQ
'You must use the $ after the object you reference in the spreadshee

ExcelData.SelectCommand.Connection.ConnectionStrin g = strCon
ExcelData.SelectCommand.Connection.Open()

For Each xlWs In xlApp.Workbooks.Open(FileName, [readOnly]).Worksheet
strSql = "SELECT * FROM [" & xlWs.Name.ToString & "$]
ExcelData.SelectCommand.CommandText = strSq
ExcelData.Fill(dsExcel, "Excel"
'call method to write datase
'WriteDataSet(dsExcel
Next xlW

ExcelData.SelectCommand.Connection.Close(
ExcelData.SelectCommand.Connection.Dispose(
'Free the Object
dsExcel = Nothin
ExcelData = Nothin
xlApp.Quit(
xlWs = Nothin
xlWb = Nothin
xlApp = Nothin

this code works fine, without giving any "read-write " dialogue.

1) Have explicitly opened and closed the connection outside the loop
2) Have set the ExcelData object to nothing, else am able to see the "Excel" application process still running even after closing this sample code application
3) There are 2 declarations of dsExcel, which I have removed

Hope this helps.

Regards
Annapoorni
Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dianna K | last post by:
I am opening, reading and extracting an Excel spreadsheet in .Net (VB). It seems to work fine, however, when I am finished and I open up Excel and try to open up the file a message pops up "File Now...
2
by: Vanessa | last post by:
I need to read/extract data from an Excel file using ASP. However, the Excel file is not in regular tabular format; instead, it is actually a form. Therefore, it contains many checkbox and merged...
9
by: Brian Hanson | last post by:
Hi, I have an unusual problem that just showed its ugly head at a pretty bad time. I have an asp.net (VB) app that takes data from an Excel sheet and puts it into SQL Server. I get the data...
1
by: J Daniel Melton | last post by:
Hello, I am using late binding in a managed VC++ .NET 2003 application. I used KB 302902 (for C#) as a starting point and converted it to managed C++. I built a managed class that is intantiated...
4
by: Seok Bee | last post by:
Dear Experts, I have created a script to extract the Event Logs from the system into an excel sheet. The logs are separated into 2 worksheets (Application Log and System Log). After this excel...
8
by: Johnny | last post by:
Hi all: I have an ASP.NET form that reads an Excel file and populates a datagrid. If I load the form in IE on the server, and select a local file, the code works fine. However if I load the form...
3
by: maylee21 | last post by:
hi, anyone can help me figure out how to read data from a text file like this: 10980012907200228082002 and extract the data according to this kind of format: Record type 1 TY-RECORD ...
1
by: manishabh77 | last post by:
I will be obliged if anybody can help me with this problem: I am trying to extract data from an excel sheet that matches IDs given in column 4 of the excel sheet.I have stored those query IDs in an...
0
by: todubhai | last post by:
I am using the following code to extract the sheet names from excel: (See attached code) private String GetExcelSheetNames(string sConnectionString) { OleDbConnection objConn...
2
by: Riak | last post by:
Hellow Helpers: I am doing data entry job manually and data is huge. Now I was told to write/get some sort of program/script which can do this job quickly, otherwise I will loose job. I am good...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.