| | |
Import/Export Excel
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2007
Posts: 44
Reputation:
Solved Threads: 0
I am trying to import and export to/from excel.
This needs to be able to be done on a weekly basis.
I have managed to find a couple of ways of doing this, but I need a way to set column width and row colours and wondered if anyone might know of a way of doing this?
This needs to be able to be done on a weekly basis.
I have managed to find a couple of ways of doing this, but I need a way to set column width and row colours and wondered if anyone might know of a way of doing this?
One thing I have learnt is it is not what you know, but knowing what you don't that makes the difference.
•
•
Join Date: Aug 2007
Posts: 44
Reputation:
Solved Threads: 0
I have a new problem now!
I am trying to use bulk copy to import the excel spreadsheet, but I keep getting the following error:
The given ColumnMapping does not match up with any column in the source or destination.
I have tries a blank table and one that matches the headers used in the spreadsheet, but this has not made a difference.
What am I missing?
I am using Vista and have Office 2007 installed although the spreadsheet is on Office 2003 format.
The code I am using is:
Dim opendlg As New OpenFileDialog
opendlg.Filter = "Excel Files (*.xls)|*.xls|All Files (*.*)|*.*"
If opendlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim pathandfile As String = opendlg.FileName
Dim connection As OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "data source=" & pathandfile & ";Extended Properties='Excel 8.0;'")
Dim Command = New OleDb.OleDbCommand("select * from [Cornwall$]", connection)
connection.Open()
Dim dr As Data.IDataReader = Command.ExecuteReader
Dim bulkCopy As SqlClient.SqlBulkCopy = New SqlClient.SqlBulkCopy("Data Source=.\SQLEXPRESS;Initial Catalog=CoaST GTBS Database;Integrated Security=True")
bulkCopy.DestinationTableName = "LocalIn"
bulkCopy.WriteToServer(dr)
Dim adapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter("select * from [Cornwall$]", connection)
adapter.Fill(Me.CoaST_GTBS_DatabaseDataSet.LocalIn)
connection.Close()
The error is shown at the bulkcopy.writetoserver(dr).
Thank you for any assistance.
I am trying to use bulk copy to import the excel spreadsheet, but I keep getting the following error:
The given ColumnMapping does not match up with any column in the source or destination.
I have tries a blank table and one that matches the headers used in the spreadsheet, but this has not made a difference.
What am I missing?
I am using Vista and have Office 2007 installed although the spreadsheet is on Office 2003 format.
The code I am using is:
Dim opendlg As New OpenFileDialog
opendlg.Filter = "Excel Files (*.xls)|*.xls|All Files (*.*)|*.*"
If opendlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim pathandfile As String = opendlg.FileName
Dim connection As OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "data source=" & pathandfile & ";Extended Properties='Excel 8.0;'")
Dim Command = New OleDb.OleDbCommand("select * from [Cornwall$]", connection)
connection.Open()
Dim dr As Data.IDataReader = Command.ExecuteReader
Dim bulkCopy As SqlClient.SqlBulkCopy = New SqlClient.SqlBulkCopy("Data Source=.\SQLEXPRESS;Initial Catalog=CoaST GTBS Database;Integrated Security=True")
bulkCopy.DestinationTableName = "LocalIn"
bulkCopy.WriteToServer(dr)
Dim adapter As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter("select * from [Cornwall$]", connection)
adapter.Fill(Me.CoaST_GTBS_DatabaseDataSet.LocalIn)
connection.Close()
The error is shown at the bulkcopy.writetoserver(dr).
Thank you for any assistance.
One thing I have learnt is it is not what you know, but knowing what you don't that makes the difference.
You are missing the field mapping just before the Destination Table.
' Set up the column mappings by name.
Dim mapID As New _
SqlBulkCopyColumnMapping("ProductID", "ProdID")
bulkCopy.ColumnMappings.Add(mapID)
You have to do it for all the fields
' Set up the column mappings by name.
Dim mapID As New _
SqlBulkCopyColumnMapping("ProductID", "ProdID")
bulkCopy.ColumnMappings.Add(mapID)
You have to do it for all the fields
•
•
Join Date: Aug 2007
Posts: 44
Reputation:
Solved Threads: 0
Thank for this binoj_daniel, will will start typing.
Is there anything in the copy I am using that would allow the colour of rows to be able to be picked up?
I need to be able to pick these up from the spreadsheet and also copy back to a spreadsheet.
Is there anything in the copy I am using that would allow the colour of rows to be able to be picked up?
I need to be able to pick these up from the spreadsheet and also copy back to a spreadsheet.
One thing I have learnt is it is not what you know, but knowing what you don't that makes the difference.
•
•
Join Date: Aug 2007
Posts: 44
Reputation:
Solved Threads: 0
binoj-daniel, have just tried adding the code you gave me, but am still showing the same error.
When I had a few spelling mistakes I was give the error showing that there wasn't X column.
Do you have any idea where to start looking?
When I had a few spelling mistakes I was give the error showing that there wasn't X column.
Do you have any idea where to start looking?
One thing I have learnt is it is not what you know, but knowing what you don't that makes the difference.
so you mapped all the columns? I would suggest you to create a test table with 2 columns and try this first. This way you can figure out where is the problem.
•
•
Join Date: Aug 2007
Posts: 44
Reputation:
Solved Threads: 0
Thank you for your suggestion, if only I had been thinking this would have been obvious.
I also found some sizing problems.
Can something along the lines about be used to pick up the row colours?
I also found some sizing problems.
Can something along the lines about be used to pick up the row colours?
One thing I have learnt is it is not what you know, but knowing what you don't that makes the difference.
![]() |
Similar Threads
- import textfile to excel (Visual Basic 4 / 5 / 6)
- Import excel records into ASP database (ASP)
- Specify row/columns when export to Excel from DataGrid? (ASP.NET)
- Import info from excel to access (MS Access and FileMaker Pro)
- Export from Excel help needed (Mac Software)
- Import/export tab delimited file (PHP)
- How to export excel data to a search engine? (MS Access and FileMaker Pro)
Other Threads in the VB.NET Forum
- Previous Thread: Lost path
- Next Thread: Send images to Crystal Reports - VB.NET
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account arithmetic array basic beginner bing browser button buttons center check code crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel fade file-dialog filter forms ftp generatetags google hardcopy html images input insert intel internet mobile monitor net networking objects open output panel passingparameters pdf picturebox picturebox1 port position print printing problem save searchbox searchvb.net select serial settings shutdown soap sqlserver survey table tcp temperature text textbox timer timespan toolbox transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode year





