OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-02-2004, 04:17
LxRAE
Guest
 
Posts: n/a
Default Read Data from Excel File

Hi,
i want to read the data from the attached excel file.
I have problems displaying the turkish chars.
after my import script, all special C and S are converted to plain C and S

any suggestions ?
Attached Files
File Type: xls data.xls (13.5 KB, 892 views)
Reply With Quote
  #2  
Old 12-02-2004, 14:23
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default Re: Read Data from Excel File

LxRAE,

Sorry for the delay...

One way to solve the problem is to make sure that Turkish code page is set as default on your Windows. Everything should work OK then.

However if you want to use any other Windows language (e.g. English, Greek, etc) and still want to get Turkish text into CorelDRAW 11, here is one way to do it:

Code:
Option Explicit

Private Declare Function WideCharToMultiByte Lib "kernel32" _
            (ByVal CodePage As Long, ByVal dwFlags As Long, _
            ByRef lpWideCharStr As Integer, ByVal cchWideChar As Long, _
            ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, _
            Optional ByVal lpDefaultChar As Long = 0, _
            Optional ByVal lpUsedDefaultChar As Long = 0) As Long
            
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" _
            (ByVal lpString As String) As Long

Sub ReadExcel()
    Dim cnn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim s As String
    
    ' Open the connection to an Excel file
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=C:\data.xls;" & _
        "Extended Properties=""Excel 8.0; HDR=No;"""

    rs.Open "SELECT * FROM [Tabelle1$a1:a13]", cnn, _
        adOpenForwardOnly, adLockReadOnly
    
    s = ""
    
    While Not rs.EOF
        If s <> "" Then s = s & vbCrLf
        s = s & rs!F1
        rs.MoveNext
    Wend

    rs.Close
    cnn.Close
    Set rs = Nothing
    Set cnn = Nothing
    
    ActiveLayer.CreateArtisticText 0, 10, ConvertToANSI(s, 1254), _
                        cdrTurkish, cdrCharSetTurkish, "Arial"
End Sub

Private Function ConvertToANSI(ByVal s As String, ByVal CodePage As Long) As String
    Dim sa As String
    Dim ln As Long
    Dim str() As Integer
    Dim n As Long
    
    ln = Len(s)
    ReDim str(0 To ln)
    For n = 0 To ln - 1
        str(n) = AscW(Mid$(s, n + 1, 1))
    Next n
    str(ln) = 0
    sa = Space$(ln)
    WideCharToMultiByte CodePage, 0, str(0), ln, sa, ln
    
    ConvertToANSI = Left$(sa, lstrlen(sa))
End Function
I have created a function ConvertToANSI which essentially translates Turkish character from Unicode into the extended character set of the current Windows code page. This tricks CorelDRAW into thinking that everything is OK and by explicitly specifying the language and charset when creating the text, everything looks OK on the screen (make sure you use a Unicode font, such as Arial in the above example).

The above example is also useful in that it shows how to use ADO (ActiveX Data Objects) to access excel file without even launching Excel. (Just make sure you add a reference to "Microsoft ActiveX Data Objects 2.* Library" from your VBA project => Go to Tools>References in CorelDRAW's VBA Editor).

Now, with CorelDRAW 12 everything is so much simpler because Draw 12 is a Unicode application now, so the tricks with playing with codepages is gone now:

Code:
Sub ReadExcel()
    Dim cnn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim s As String
    
    ' Open the connection to an Excel file
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=C:\data.xls;" & _
        "Extended Properties=""Excel 8.0; HDR=No;"""

    rs.Open "SELECT * FROM [Tabelle1$a1:a13]", cnn, _
        adOpenForwardOnly, adLockReadOnly
    
    s = ""
    
    While Not rs.EOF
        If s <> "" Then s = s & vbCrLf
        s = s & rs!F1
        rs.MoveNext
    Wend

    rs.Close
    cnn.Close
    Set rs = Nothing
    Set cnn = Nothing
    
    ActiveLayer.CreateArtisticText 0, 10, s, Font:="Arial"
End Sub
Reply With Quote
  #3  
Old 13-02-2004, 02:08
LxRAE
Guest
 
Posts: n/a
Default

(!) THANK YOU SIR - up to now i didnt try the code but i'm sure it will fit.

Reply With Quote
  #4  
Old 13-04-2004, 10:19
olympiatr
Guest
 
Posts: n/a
Default Re: Read Data from Excel File

Quote:
Originally Posted by LxRAE
Hi,
i want to read the data from the attached excel file.
I have problems displaying the turkish chars.
after my import script, all special C and S are converted to plain C and S

any suggestions ?

SELAM SANIRIM TÜRKSÜNÜZ, BİLGİ ALIŞVERİŞİNDE BULUNMAK İSTERİM. İYİ GÜNLER DİLİYORUM.
Reply With Quote
  #5  
Old 14-04-2004, 00:43
LxRAE
Guest
 
Posts: n/a
Default

muah
buddy, i have no idea what u wan me to tell
Reply With Quote
  #6  
Old 14-04-2004, 03:10
olympiatr
Guest
 
Posts: n/a
Default

: ))) lol.... i thought that you are Turkish, what a fool i am.. anyway no problem pal, enjoy your self. good day...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
delete vba project from cdr file hotairballoon CorelDRAW/Corel DESIGNER VBA 1 18-05-2005 10:08
File Convertor to do transpararent TIFFs dan CorelDRAW/Corel DESIGNER VBA 8 22-12-2004 14:23
Is Corel to Excel data exchange possible? alex69 CorelDRAW/Corel DESIGNER VBA 8 24-06-2004 05:52
reading data from file and generate "labels" LxRAE CorelDRAW/Corel DESIGNER VBA 4 23-01-2004 05:05
Open - Resize - Savefile in Photo Paint greenee Corel Photo-Paint VBA 2 28-06-2003 04:54


All times are GMT -5. The time now is 21:42.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com