SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


CSV to Excel


CSV to Excel

Author
Message
Admingod
Admingod
Old Hand
Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)

Group: General Forum Members
Points: 313 Visits: 1072
How to automate the process of converting csv file to excel file?
MyDoggieJessie
MyDoggieJessie
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6662 Visits: 7393
Crude, but this will work, just loop through a directory (if you are able to execute xp_cmdshell, if not I'm sure there's a powershell script lingering around)
DECLARE
@Filepath varchar(75),
@file varchar(25),
@Cmd varchar(150)
SET @file = 'test.csv'
SET @filepath = 'C:\'
SET @cmd = 'ren "' + @filepath + @file + '" "' + REPLACE(@file, 'csv', 'xls') + '"'
PRINT @cmd

EXEC xp_cmdshell @cmd, NO_OUTPUT



Why would you want to do this via TSQL?

______________________________________________________________________________
"Never argue with an idiot; They'll drag you down to their level and beat you with experience" ;-)
Want a cool Sig
Want a cool Sig
SSC-Addicted
SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)SSC-Addicted (414 reputation)

Group: General Forum Members
Points: 414 Visits: 705
MyDoggieJessie (1/22/2013)
Crude, but this will work, just loop through a directory (if you are able to execute xp_cmdshell, if not I'm sure there's a powershell script lingering around)
DECLARE
@Filepath varchar(75),
@file varchar(25),
@Cmd varchar(150)
SET @file = 'test.csv'
SET @filepath = 'C:\'
SET @cmd = 'ren "' + @filepath + @file + '" "' + REPLACE(@file, 'csv', 'xls') + '"'
PRINT @cmd

EXEC xp_cmdshell @cmd, NO_OUTPUT



Why would you want to do this via TSQL?


This will only rename the files and not convert the CSV to XLS binary file.
The question still remains why would you do it in SQL?
I think it would work with SSIS. To read the CSV files in and then spit out as Excel.
There are converters out in the net, just have to search for it.

---------------------------------------------------------------
Mike Hahn - MCSomething someday:-)
Right way to ask for help!!
http://www.sqlservercentral.com/articles/Best+Practices/61537/
I post so I can see my avatar Hehe
I want a personal webpage Cool
I want to win the lotto :-D
I want a gf like Tiffa w00t Oh wait I'm married!:-D
Admingod
Admingod
Old Hand
Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)

Group: General Forum Members
Points: 313 Visits: 1072
I couldnt load the data from CSV file to SQL Table in correct format, some reason your script is not converting to .xls file?

Thanks
Admingod
Admingod
Old Hand
Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)

Group: General Forum Members
Points: 313 Visits: 1072
I tried with SSIS it didnt work. The data are separated with double and single codes, while loading from CSV table its not getting the data in right format.However, when u load you convert to .xls and load to sql server table it works perfect.

Thanks
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27259 Visits: 13268
Admingod (1/24/2013)
I tried with SSIS it didnt work. The data are separated with double and single codes, while loading from CSV table its not getting the data in right format.However, when u load you convert to .xls and load to sql server table it works perfect.

Thanks


SSIS should work. Can you explain a bit more about "data are separated with double and single codes"?


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Admingod
Admingod
Old Hand
Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)

Group: General Forum Members
Points: 313 Visits: 1072
below data is in CSV file....

"test, test1","xyz name","some id"
Admingod
Admingod
Old Hand
Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)

Group: General Forum Members
Points: 313 Visits: 1072
more sample data....


below data is in CSV file....

"test, test1","xyz name","some id"
"test, test1,test2","xyz name","some id"
"test","xyz name","some id"
"test, test1,test2,test3","xyz name","some id"
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27259 Visits: 13268
So you get a csv file with a comma delimiter and a double quote text qualifier. What's the issue with SSIS?


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Admingod
Admingod
Old Hand
Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)Old Hand (313 reputation)

Group: General Forum Members
Points: 313 Visits: 1072
column 1 is population into different columns instead of one column?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search