Solved

Export data to excel file and create a chart

Posted on 2007-04-11
12
1,678 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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,…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

757 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

22 Experts available now in Live!

Get 1:1 Help Now