Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Text File Encode to UTF-8_Unicode specific

Dear colleagues,
Is there any way to change/specify text file encoding to
UTF-8(Unicode) specific from VBA. I export some data table from Excel
to text file and manage to specify encode for such file 'just' as
Unicode, but the problem is that I need the encode to be exactly
UTF-8_Unicode. I have done this (export and encode setting) through
Excel_VBA embeded method 'WorkSheet.SaveAs' 'Path_FileName.Extension',
FileFormat:=xlUnicodeText. Excel_VBA offers some 45 xlFileFormat
constants but among them there is no such as 'UTF-8_Unicode'. I suppose
that 'SaveAs' method is a wraper for some WinAPI function which actualy
perfom such encode change, by aplying the value of FileFormat
argument(in case =xlUnicodeText the value is 42). In Windows XP there
is an option to perform manual encode change via general(not
Office/Excel) dialog box 'SaveAs' which contain 'Encode' ComboBox with
option 'UTF-8' specific. So I have try to do the same through VBA code,
but WinAPI function 'SetFileAtributes' doesn't offer such option. Also
through VBA- 'CreateObject(Scripting.FileSystemObject)' I can't find
the way to specify/change File_Object encoding to UTF-8 specific.
Wider view: I need the exact UTF-8_Unicode Encode, because the data
from such text file, further on, has to be imported into MySQL Server
table, by using 'LOAD DATA INFILE', and MySQL, on the Client side,
accepts(from all Uncode formats) only the UTF-8_Unicode. The text file
exported from Excel(FileFormat:=xlUnicodeText), s.c. 'Plane_Unicode'
isn't correctly readable in MySQL(doesn read correctly 'FIELDS
TERMINATED BY' and 'LINES TERMINATED BY' i.e. fields-lines delimiter).
But, when I change file encode MANUALY(via Windows general 'SaveAs'
dialog box) from 'Plane'(xlUnicodeText)_Unicode to Unicode_'UTF-8',
then MySQL loads data to table correctly. I have try to determine
fields-lines delimiter in 'Plane'(xlUnicodeText)_Unicode text file, by
re-import such file back to Excel and Excel DataImport Wizard see the
'Tab' as fields delimiter but MySQL doesn't or doesn't recognize it.
So please, I will be very thankfull for any solution or advice
regarding this problem, Thank You in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 214
Default Text File Encode to UTF-8_Unicode specific

You can try:

Sub Encode(ByVal sPath$, Optional SetChar$ = "UTF-8")
With CreateObject("ADODB.Stream")
..Open
..LoadFromFile sPath ' Loads a File
..Charset = SetChar ' sets stream encoding (UTF-8)
..SaveToFile sPath, 2 ' adSaveCreateOverWrite
..Close
End With
End Sub

Regards,
MP

a écrit dans le message de news:
...
Dear colleagues,
Is there any way to change/specify text file encoding to
UTF-8(Unicode) specific from VBA. I export some data table from Excel
to text file and manage to specify encode for such file 'just' as
Unicode, but the problem is that I need the encode to be exactly
UTF-8_Unicode. I have done this (export and encode setting) through
Excel_VBA embeded method 'WorkSheet.SaveAs' 'Path_FileName.Extension',
FileFormat:=xlUnicodeText. Excel_VBA offers some 45 xlFileFormat
constants but among them there is no such as 'UTF-8_Unicode'. I suppose
that 'SaveAs' method is a wraper for some WinAPI function which actualy
perfom such encode change, by aplying the value of FileFormat
argument(in case =xlUnicodeText the value is 42). In Windows XP there
is an option to perform manual encode change via general(not
Office/Excel) dialog box 'SaveAs' which contain 'Encode' ComboBox with
option 'UTF-8' specific. So I have try to do the same through VBA code,
but WinAPI function 'SetFileAtributes' doesn't offer such option. Also
through VBA- 'CreateObject(Scripting.FileSystemObject)' I can't find
the way to specify/change File_Object encoding to UTF-8 specific.
Wider view: I need the exact UTF-8_Unicode Encode, because the data
from such text file, further on, has to be imported into MySQL Server
table, by using 'LOAD DATA INFILE', and MySQL, on the Client side,
accepts(from all Uncode formats) only the UTF-8_Unicode. The text file
exported from Excel(FileFormat:=xlUnicodeText), s.c. 'Plane_Unicode'
isn't correctly readable in MySQL(doesn read correctly 'FIELDS
TERMINATED BY' and 'LINES TERMINATED BY' i.e. fields-lines delimiter).
But, when I change file encode MANUALY(via Windows general 'SaveAs'
dialog box) from 'Plane'(xlUnicodeText)_Unicode to Unicode_'UTF-8',
then MySQL loads data to table correctly. I have try to determine
fields-lines delimiter in 'Plane'(xlUnicodeText)_Unicode text file, by
re-import such file back to Excel and Excel DataImport Wizard see the
'Tab' as fields delimiter but MySQL doesn't or doesn't recognize it.
So please, I will be very thankfull for any solution or advice
regarding this problem, Thank You in advance.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text box to encode information to worksheets. joromajr Excel Discussion (Misc queries) 1 July 30th 08 02:19 PM
assign values to specific cells in an excel sheet through text file s_pushparaj Excel Discussion (Misc queries) 2 May 11th 08 10:09 PM
URL Encode Dave Excel Worksheet Functions 0 June 6th 07 04:11 PM
[Excel, VB6] Encode text before sending to Linux server JoTak Excel Programming 1 November 28th 05 10:27 PM
WRITING TO A TEXT FILE WITH SPECIFIC FORMAT [email protected] Excel Programming 2 December 27th 03 05:04 AM


All times are GMT +1. The time now is 06:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"