Solved

Export data to excel file and create a chart

Posted on 2007-04-11
12
1,679 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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…

948 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now