Click here to Skip to main content
16,016,562 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So far I have to save the workbook first and then I have to pass the full path of the file to read the data from the sheet.

Is there any way out that I can read the file without saving it.

Sorry for my terrible English.

What I have tried:

VB
Dim WB As Microsoft.Office.Interop.Excel.Workbook =          Globals.ThisAddIn1.Application.ActiveWorkbook
Dim dt As New System.Data.DataTable()
Dim strWorkbookName As String
Dim strConn As String
Dim strExcelSheet As String
Dim xlConn As OleDbConnection
Try
WB.SaveAs("myWorkBook_" + DateTime.Now.ToString("yyyyMMdd_HHmmss"))
strWorkbookName = WB.FullName  (here I get the full path of my saved excel workbook)
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strWorkbookName + ";Extended Properties='Excel 12.0 Xml;HDR=Yes;IMEX=1'"
xlConn = New OleDbConnection(strConn)
xlConn.Open()
              
dt = xlConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
If dt IsNot Nothing OrElse dt.Rows.Count > 0 Then
     strExcelSheet = dt.Rows(0)("table_name").ToString()
     Dim da As New OleDbDataAdapter("SELECT * FROM ["+strExcelSheet +"]", xlConn)
     da.Fill(dsSave, strExcelSheet)
End If

Catch ex As Exception
        MsgBox("Error"+ ex.Message.ToString())    
Finally
        xlConn.Close()  
End Try
Posted
Updated 17-Mar-16 20:55pm
v4
Comments
Richard MacCutchan 18-Mar-16 5:37am    
No, the ACE engine can only read from a file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900