Jump to content

Reading EXCEL (XLS) documents with other charactersets


xtentic

Recommended Posts

Hi all,

First i appoligise for my bad english. ;)

For a friend i need to create a script that can read XLS documents. Well that's not the problem anymore... with the code (down here) i've already writen i can read tru the document. All rows and colums... but there one fault.. ROW A has normal characters (like A-Z) but row C contains thai carakters (using font : Angsana New in EXCEL or WORD). When i run the following script i see the words on ROW A displayed correctly but on row C wich contains THAI language words i only see ??? ? ? ? ?????.

I've been searching over the internet for days but havent found why! i've tried alot of scripts (both free or wich i need to pay for) but only a pricy script (like 80$) would show the carakters in ROW C correctly.

The script i wrote is.

[code]<?
    $excel = new COM("excel.application") or die("Unable to instanciate excel"); 

    //bring it to front 
    $excel->Visible = 1;//NOT
    //dont want alerts ... run silent 
    $excel->DisplayAlerts = 1; 

    //open  document 
    $excel->Workbooks->Open("d:/excel.xls"); 

    for ($h = 1; $h <= 3; $h++)
    {
        $book  = $excel->Workbooks(1);
        $sheet = $book->Worksheets($h);

        echo "<table>\n";
        //Wtite row
        for ($i = 1; $i <= 150; $i++)
        {
            echo "<tr>\n";
            //write colom
            for ($j = 1; $j <= 5; $j++)
            {
                $cell = $sheet->Cells($i, $j); // #Select the cell (Row Column number)
                $cell->activate;              // #Activate the cell
           
                if($cell->value == '0')
                {
                    $td = "";
                }
                else
                {
                    $td = $cell->value;
                }

                echo "<td>" . $td . "</td>\n"; // #write the cell
            }
            echo "</tr>\n";
        }
        echo "</table>\n";
    }

    //closing excel 
    $excel->Quit(); 
?>
[/code]

the file excel.xls contains a couple of words on row A and the translation on row C.

I hope someone has a possible sollution for this problem!.

Thank you all for reading! If you don't have a anwser and you think someone you know could know the answer!!!, please point them to this topic!..
Link to comment
Share on other sites

[quote author=xtentic link=topic=114045.msg463824#msg463824 date=1162839925]
Hi all,

First i appoligise for my bad english. ;)

For a friend i need to create a script that can read XLS documents. Well that's not the problem anymore... with the code (down here) i've already writen i can read tru the document. All rows and colums... but there one fault.. ROW A has normal characters (like A-Z) but row C contains thai carakters (using font : Angsana New in EXCEL or WORD). When i run the following script i see the words on ROW A displayed correctly but on row C wich contains THAI language words i only see ??? ? ? ? ?????.[/quote]

Hi xtentic,

I understand the problem you're having (sort of) and I know how to get Excel to display the hex codes (or whatever they're called) rather than the foreign language characters, so as to output a .txt file that doesn't have ???? wherever the foreign language characters should be.

(see explanation at http://www.phpfreaks.com/forums/index.php/topic,110192.msg444978.html#msg444978 0 ).

Not sure what you're doing with the language bits after calling them up, but if it's for a webpage, browsers will display the characters relating to the hex codes accurately, ie if you use the generated hex codes from the Excel conversion in place of the Thai characters.

Hope this makes sense :)  please ask, if not.

Regards,

Penny.
Link to comment
Share on other sites

Hi,

I understand the solution you have offerd me. But it's not the kind of solution i was hoping for. The list changes regularly so i need to convert the given data from the excel cell in realtime. Some scripts on the internet can do that... But as writen before they cost alot. And i think that the solution should me not that hard...

Thanks for your support! :)
Link to comment
Share on other sites

[quote author=xtentic link=topic=114045.msg463919#msg463919 date=1162849882]
Hi,

I understand the solution you have offerd me. But it's not the kind of solution i was hoping for. The list changes regularly so i need to convert the given data from the excel cell in realtime. Some scripts on the internet can do that... But as writen before they cost alot. And i think that the solution should me not that hard...

Thanks for your support! :)[/quote]

You're welcome :)  sorry the info wasn't exactly what you needed for your application.

Regards,

Penny.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.