Showing posts with label cell. Show all posts
Showing posts with label cell. Show all posts

Monday, March 19, 2012

Import data using excel file!

I import data to my Database(SQL Server 2000).

I use excel file to import, some file is ok, but wiht some file, some data cell in these is lost.

What do I do now?

What types of cells are lost? How do you import data?|||

I import data by using "DTS Import/Export Wizard" then, "select Microsoft Excel 97-2000".

In my excel file, I tried to use types(general, Number, Text) to format cells but not sucessfull . any ideas to solve my problem, sir? I appeciate your help.

note: If you need that excel file for test, pls send me your email addr.

|||

I believe DTS using Jet OLEDB provider to do the import and, I believe you could specify connection string for it. If ys, then you need to IMEX=1 property to the connection string. It will force Jet to treat all the values a strings and you should be able to see all the values. Whta happens is the Jet is using several first rows to identify type of the columns. If specific column contains mixed types text with numbers ot dates), then some values will be lost. Your connection string will look like

"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\somepath\ExcelFile.xls;" & _
"Extended Properties=""EMEX=1"";"

If you need to preserve original types of cells, then you would need to use your own code to read content of Excel. For example, you could use Excel DOM model to read the data or some other tool, but not Jet

Wednesday, March 7, 2012

Import cell data from XLS into SQL table

I'm trying to use DTS to import data from an XLS into a SQL table.

It works fine in that it INSERT's the data. However, I need it to
UPDATE the table, based upon a ProjectID. Can this be done?

Can a DTS package be fired from a SP using parameters?
Eg UPDATE tProjects SET MyField1=XLS.Sheet1.CellA1,
MyField2=XLS.Sheet2.CellA1 WHERE ProjectID = @.ProjectID.

Also, it must handle dynamic XLS file names, eg 981-Budget.xls,
513-Budget.xls, xyz-Budget.xls

Is this the best way to go? Other suggestions most welcome?

Thanks everyone in advance!Sorry, you also has another question:

"Can a DTS package be fired from a SP using parameters? "

Yes, you have to run the DTSRUn in a cmdshell with XP_cmdshell and hand
over the paramters to global paramerters defined in the DTS package.
(consider the /A switch and look in the BOL for more syntax
information)

HTH, Jens Suessmeyer.|||I would do the querying once and put the data in a temporary table:

<SQLCode>
DECLARE @.Folder varchar(200)
DECLARE @.Filename varchar(200)
DECLARE @.Workbook varchar(200)

DECLARE @.Sqlstring varchar(4000)

SET @.FileName = 'SomeSheet.xls'
SET @.Folder = 'C:\SomeFolder\'
Set @.Workbook = 'SomeWorkbook'

SET @.SQLString = 'SELECT * FROM OpenDataSource(
''Microsoft.Jet.OLEDB.4.0'',''Data Source="' + @.Folder + @.FileName +
'";User ID=Admin;Password=;Extended properties=Excel 5.0'')...' +
@.Workbook

Create Table #SomeTable
(
<YourTableDefinitionhere>
)

INSERt INTO #SomeTable
EXEC(@.SQLString)

</Do anything with the data
</SQLCode
HTH, Jens Suessmeyer.