Link to home
Start Free TrialLog in
Avatar of VanNam
VanNam

asked on

Export data to excel file and create a chart

Hi all,

I'm working with excel file in php. I used Spreadsheet_Excel_Writer to write data to an excel file, but now I want to export a chart in that excel.  
My idea:
        I think I could use macro. I wrote a macro in a nested excel file in server. And when use Spreadsheet_Excel_Writer, data will be stored in this excel file. After all, when user open this excel chart will be created.

But It's impossible. Because when use Spreadsheet_Excel_Writer, excel file's new created, and macro 's deleted 2.

How can you help me to solve this problem? [export data to excel file and create a chart with these data rows]
I think if we can open an exist file (of course, don't delete its macro) or there's a way to copy data from an excel file to another excel file, Problem will be solved.

Best Regards,
VanNam
Avatar of TeRReF
TeRReF
Flag of Netherlands image

Can you still save as HTML even if there are macro's defined? If so, you could just parse the HTML file and create them like that...
Avatar of VanNam
VanNam

ASKER

Hi Terref,
Can u tell me obviously about your solution?

I wrote it above. I wrote a NESTED excel file, and a macro in this file.  But this macro' s cleared whenever I use SpreadSheet_Excel_Writer to write data to excel file.  And my nested file's a absolutely new file now :|

and about techs to use Spread_Excel_Writer plz <a href='http://pear.php.net/package-info.php?pacid=156'> check here</a>
ASKER CERTIFIED SOLUTION
Avatar of TeRReF
TeRReF
Flag of Netherlands image

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
Avatar of VanNam

ASKER

Thank Terref a lots,

I am using japanese character; so when i write data to htm file, character and fonts are broken.
Have you got any idea for my problem?
Did you try to convert the data to htmlentities first?

Something like:

$data = htmlentities($data, ENT_COMPAT, "EUC-JP");

Have a look here:
http://nl2.php.net/htmlentities

Since the second and third parameter can be quite important and there is also another Japanese charset supported (Shift_JIS)

Hope this helps...
Avatar of VanNam

ASKER

Hi,

Thx Terref for your help.  I'm writing some functions to insert data into excel-html file.  I wil try to use your idea :D. I think that it'll be OK. And I know my problem's solved.

See you in another question ! :)
You're welcome :)
Avatar of VanNam

ASKER

Hi Terref,

I had created an excel file with macro like you said. But some things happen:

    1. When save as .xls file to .htm file, macro will save in file .mso in folder of html file ( 123.htm --> folder 123_files)
    2. I create a nested excel file in server to help users can download .xls file with macro to their computer. And when they open this file, there'll be a chart in their excel file.

But in .xls file users downloaded, there won't be  macro embbed in it. Because macro's saved in mso file in html folder and this file is saved in server ;(

How can i merge macro into .xls file when users download xls file from server?

VanNam
Mmm, tricky. Why don't ou create a zip file (with both files in it) on the fly after parsing the htm/xls file? Users download the zip file and will have all necessary files available on their computer. Have a look at these functions:
http://php.net/zip
Avatar of VanNam

ASKER

Hi Terref,

Can you show me a full-example uses zip file plz ?
Avatar of VanNam

ASKER

Ok, all problems're solved. And it's here: http://www.4shared.com/account/file.jsp?id=14003303&sId=52w0F0ZbcragxvTi

Thank Terref 1 more again :)
I'm glad it works :)