[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Export data to excel file and create a chart

Posted on 2007-04-11
12
Medium Priority
?
1,689 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 1500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
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…
Suggested Courses

650 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