Solved

Export data to excel file and create a chart

Posted on 2007-04-11
12
1,686 Views
Last Modified: 2008-02-20
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
0
Comment
Question by:VanNam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 18888164
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...
0
 
LVL 2

Author Comment

by:VanNam
ID: 18888274
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>
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 500 total points
ID: 18888420
My solution would drop the use of SpreadSheet_Excel_Writer and would work something like:

- Create the Excel file with all necessary stuff included.
- Save it as .htm file.
- Name the cells that need to be filled in with unique names to make parsing the file easy
- In your php application open the excel .htm file, preg_replace() / str_replace() the cells with the appropriate values
- save excel file under different name and with the xls extension (even though it's still html code). Excel will open it properly

You can both save macro's AND charts when you save your excel file as .htm. So it is possible...
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 2

Author Comment

by:VanNam
ID: 18888511
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?
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18888596
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...
0
 
LVL 2

Author Comment

by:VanNam
ID: 18896299
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 ! :)
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18896346
You're welcome :)
0
 
LVL 2

Author Comment

by:VanNam
ID: 18903816
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
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18903929
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
0
 
LVL 2

Author Comment

by:VanNam
ID: 18904334
Hi Terref,

Can you show me a full-example uses zip file plz ?
0
 
LVL 2

Author Comment

by:VanNam
ID: 18904654
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 :)
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18904815
I'm glad it works :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question