Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save a excel file as csv with UTF-8 encoding?
    primarykey
    data
    text
    <p>I have been struggling for some time with the excel problem.I have Russian characters in my excel file (2003 version) and I want to save it to a csv.But the problem is whenever I do it instead of Russian characters I am getting ??????. After going through various forums I found out that the problem is with MS excel.</p> <p>So Now I was wondering,if I could write a VB script which would read the strings from the required cells, covert them to UTF-8 encoding and store it in a text file. I have 2 problems here:</p> <ol> <li><p>Is my solution feasible or not? I have no idea if it can be done or not? Any pointers would be help full. I have trawled through net and couldn't find anything.</p></li> <li><p>As I am completely zero with VB scripting, can some body help me with a sample code please?</p></li> </ol> <p>Most importantly, if someone knows a better way of doing it please let me know.</p> <p>Thanks spanky</p> <hr> <p>I have gone through Salman's code and tried in on my excel (embedded in it). I was facing some probs and I have modified it a bit after searching through net. The modified code is given below:</p> <pre><code>Sub test() 'Modified lines Dim CONNECTION1 As New ADODB.Connection Set CONNECTION1 = New ADODB.Connection 'Set CONNECTION1 = WScript.CreateObject("ADODB.CONNECTION") 'Modified line CONNECTION1.Open "Provider=MICROSOFT.JET.OLEDB.4.0;Data Source=c:\Documents and Settings\bht1kor \Desktop \test.xls;Extended Properties=""Excel 8.0;HDR=Yes;""" Dim RECORDSET1 As New ADODB.Connection Set RECORDSET1 = New ADODB.Connection 'commented the line 'WScript.CreateObject ("ADODB.RECORDSET") RECORDSET1.Open CONNECTION1 ', 3, 1 Set rs1 = RECORDSET1.Execute("SELECT * FROM [Sheet1$]") ' Notes: ' CharacterSet 65001 is UTF-8 ' add/remove columns and change datatype to match you excel file Dim CONNECTION2 As New ADODB.Connection Set CONNECTION2 = New ADODB.Connection 'commented the line 'Set CONNECTION2 = WScript.CreateObject("ADODB.CONNECTION") CONNECTION2.Open "Provider=MICROSOFT.JET.OLEDB.4.0;Data Source=c:\Documents and Settings\bht1kor\Desktop\;Extended Properties=""text;HDR=Yes;FMT=Delimited;CharacterSet=65001;""" CONNECTION2.Execute "CREATE TABLE [output.csv] ([English] VARCHAR(200), [Swedish] VARCHAR(200), [Russian] VARCHAR(200), [Chinese Simplified] VARCHAR(200))" Dim RECORDSET2 As New ADODB.Connection Set RECORDSET2 = New ADODB.Connection 'commented the line 'Set RECORDSET2 = WScript.CreateObject("ADODB.RECORDSET") RECORDSET2.Open CONNECTION2, adOpenKeyset, adLockOptimistic 'Do Until RECORDSET1.EOF RECORDSET2.AddNew Dim i For i = 0 To RECORDSET1.Fields.Count - 1 'comented the line 'WScript.Echo RECORDSET1.Fields(i).Value RECORDSET2.Fields(i).Value = RECORDSET1.Fields(i).Value Next RECORDSET2.Update RECORDSET1.MoveNext Loop End Sub </code></pre> <p>I am still facing problems while running this code. while running the following line :</p> <p>RECORDSET2.Open CONNECTION2, adOpenKeyset, adLockOptimistic</p> <p>it is giving an run time error"Cannot start your application.The workgroup file is missing or opened exclusively by another user". I am pretty much stumped by this. Any ideas. to me it looks like probs with data source. Note:- I dont have MS access installed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload