Link to home
Start Free TrialLog in
Avatar of jocke_j_78
jocke_j_78

asked on

Using SpreadSheet_Excel_Writer with Czech letters...

Hi,
I cannot get it to work with exporting text written in czech from php to excel. I loose some letters...
The attached image shows an example of my code... I have to use a image of my code since this site (www.expert-exchange.com) automatically changes all czech letters...

And the text below shows the result in the excel worksheet

Name      Age
Vera Abrahámová      30

If you compare with the code, the second letter in Vera have been replaced...

Big thx in advance!!

//Jocke
     
code.jpg
Avatar of Arijit S
Arijit S
Flag of India image

Can you share the Writer.php code? This issue can probably be best addressed there.
Queries:
(1) Are you saying that when you pass the strings from your script to writer, then it is changing?
or
(2) When you type in your Chez text on current page, it gets converted & hence writer also prints the same converted text?

One more query:
What IDE/Editor are you using - to write your code?

Thanks & regards
Avatar of jocke_j_78
jocke_j_78

ASKER

"Can you share the Writer.php code? This issue can probably be best addressed there"
     - I am using the Pear package Spreadsheet_Excel_Writer so I have not written Writer.php myself.

"(1) Are you saying that when you pass the strings from your script to writer, then it is changing?"
     - Yes, this is correct, I have no problems saving czech letters to my database or to show them correctly on my website. It is only when I am exporting to Excel this happens.

      - For your info, I did also write an own script that exports from php to excel, and I had the same problem. So it seems to me that it is excel that are causing problems here??

"What IDE/Editor are you using - to write your code?"
      - I am using Phpdesigner 7


Thx in advance!!

//Jocke
Does this work for you?

$worksheet->setInputEncoding(“UTF-8¿);


Thanks & regards
I meant...this (previous post came a bit diff):

$worksheet->setInputEncoding("UTF-8");
I tried it now, but same result ;/
Interesting...
If we follow this flow, does it still break?
================================================================
require_once('Spreadsheet/Excel/Writer.php');
$workbook = new Spreadsheet_Excel_Writer();
$workbook->send("test.xls");
$workbook->setVersion(8);
$worksheet =& $workbook->addWorksheet("My first worksheet");
$worksheet->setInputEncoding("UTF-8");
$worksheet->write(0, 0, 'Name');
...
....
$workbook->close();
================================================================

Thanks & regards
You can use following code at first row of your pages.
header('Content-Type: text/html; charset=utf-8');
Also try work with utf8 supported editors, or save modified files by UTF8 encoding.
@iamanindian, I tried your code but I got this error when I added the line $workbook->setVersion(8). "<b>Notice</b>:  iconv() [<a href='function.iconv'>function.iconv</a>]: Detected an illegal character in input string in <b>C:\wamp\bin\php\php5.3.0\PEAR\Spreadsheet\Excel\Writer\Worksheet.php</b> on line <b>1566</b><br />"

Without the row  $workbook->setVersion(8) it failed as before...

@hakperest, I changed and saved the document with encoding UTF-8. But by doing that, everything got worser, all special characters where replaced as can be seen below.
Věra Abrahámová

Thank you both for trying to help me, this issue are taking so much more time that I could ever have guessed :/,


ASKER CERTIFIED SOLUTION
Avatar of jocke_j_78
jocke_j_78

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad to know your obstacle is removed. I will however check why Excel Writer failed...& try to put a solution here - so that if someone looks for this in future, we could offer a solution.

Best wishes