LisaJong


Hi, guys

I'm fixing some multi-language function for our application software, we use FoxPro 9.0 and SQL server.

For now, I can successfuly extract data from SQL, display it in FoxPro Form (using OLE object); or import data from Excel, then save it into SQL server (thanks to Rick Strahl, http://www.west-wind.com/presentations/foxunicode/foxunicode.asp). But then, I stuck. When I try to extract data from SQL, then export them to Excel, I always get a lot of strange mark instead of my Chinese, Japanese or Arabic data shown in SQL server. I've try to STRCONV() data to Unicode or UTF-8, it just not work. Following are how I convert data in FoxPro:

** when extract data out of SQL server, convert data into VarBinary first

SQLEXEC(nConn,"SELECT CAST(CAST(p_wname as nVarChar(4000)) AS VarBinary(8000)) AS p_wname FROM program ","temp")

**convert data into UTF-8

SELECT CAST(STRCONV(p_wname,10) AS M) p_wname FROM temp INTO CURSOR TFData

** After above steps, I can show multi-language data in form normally

** And if I want to save the data back to SQL, I need to ....

** Coonvert data back to Unicode then to VarBinary

SELECT CREATEBINARY(STRCONV(p_wname,12)) AS p_wname FROM temp INTO CURSOR TFData1

** then Convert data into nVarChar

SQLEXEC(nConn, " INSERT INTO program (p_wname) VALUES (CAST( TFData1.p_wname as nVarChar(50)))")

So how can I show data normally when exporting to Excel

Thanks a lot.



Re: Export to Excel with multi-language

dni


You may try to use a variables with STRCONV... (var1 = STRCONV(p_wname,12))....






Re: Export to Excel with multi-language

LisaJong

dni, thanks sooooooo much!

I tried to select the cursor into an array

SELECT STRCONV(p_wname,10) AS p_wname FROM temp INTO ARRAY tmpArray

And do NOT use COPY TO , but create an Excel.Application object, assign the value of that array into Excel cell by cell.

oExcel=CREATEOBJECT("Excel.Application")
oExcel.visible = .t.
oExcel.WorkBooks.ADD
oExcel.Cells(1,1).VALUE=tmpArray[1,1]
oExcel.ActiveWorkbook.SaveAs("C:\TEMP.XLS")
oExcel.Quit

Then to my surprise, it's works!

Thanks again!

Lisa