473,395 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Php code to run a macro after outputting excel sheet

28
Hello,

I have a php script that outputs an excel sheet.The user has to download macro every time he wants to run the macro on the excel sheet.

Is there anything in php where the code downloads macro also along with the excel sheet or something like a button in excel sheet itself, clicking on which the macro runs on the excel sheet.

Any help is well appreciated.

Thanks&Regards,
Shara.
Jan 18 '08 #1
4 16052
shara
28
Hello,

Please consider the query, as its important for me to solve it.

I've been trying to search for a solution through out the day, but its of no use.

Any help to solve the problem in some other way is also welcome.

Thanks&Regards,
Shara.

Hello,

I have a php script that outputs an excel sheet.The user has to download macro every time he wants to run the macro on the excel sheet.

Is there anything in php where the code downloads macro also along with the excel sheet or something like a button in excel sheet itself, clicking on which the macro runs on the excel sheet.

Any help is well appreciated.

Thanks&Regards,
Shara.
Jan 18 '08 #2
Shara,

I have a couple of questions regarding your posts.

1. Is there only one user affected in this scenario? ie. Custom report, etc? If so, an easy way to do this would be to have the user save the macro code into the PERSONAL.XLS file on the local machine(or A/D profile, etc) and assign a short-cut key to the macro. This way when the user exports the data, he/she can just use a two-key shortcut to achieve the desired result.

2. Is this a dynamic report or this a static page that is generated by a static backend? If it is a static file, then I would suggest writing the export data to a file server-side that already contains the macro and the corresponding command button. Then have the user download the file from the server after your script outputs/writes the data. *Note: Depending on network security settings, having the user download active macro content may not be a viable solution.

If this is a dynamic report that affects a substantial amount of users, then I would suggest doing research on the Excel API call. Once you get in, you should be able to execute macro code that you would escape in the php script.

Hope this helps.

Regards,
Jenkins
Jan 18 '08 #3
shara
28
Hello Jenkins,

This is a dynamic report that affects a substantial amount of users.I'll try the proposed.

Thanks for your help.

Regards,
Shara.


Shara,

I have a couple of questions regarding your posts.

1. Is there only one user affected in this scenario? ie. Custom report, etc? If so, an easy way to do this would be to have the user save the macro code into the PERSONAL.XLS file on the local machine(or A/D profile, etc) and assign a short-cut key to the macro. This way when the user exports the data, he/she can just use a two-key shortcut to achieve the desired result.

2. Is this a dynamic report or this a static page that is generated by a static backend? If it is a static file, then I would suggest writing the export data to a file server-side that already contains the macro and the corresponding command button. Then have the user download the file from the server after your script outputs/writes the data. *Note: Depending on network security settings, having the user download active macro content may not be a viable solution.

If this is a dynamic report that affects a substantial amount of users, then I would suggest doing research on the Excel API call. Once you get in, you should be able to execute macro code that you would escape in the php script.

Hope this helps.

Regards,
Jenkins
Jan 28 '08 #4
shara
28
Hello Jenkins,

I tried searching for excel API call and got a code like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // set up excel
  3. $excel = new COM(”excel.application”) or die(”Unable to instantiate excel”);
  4. // run Excel silently, since we don’t want dialog boxes popping up in the background
  5. $excel->DisplayAlerts = false;
  6. // open up Excel file and select the first sheet, which contains the inputs
  7. $excel->Workbooks->Open(”model.xls”);
  8. $book = $excel->ActiveWorkbook;
  9. $sheets = $book->Sheets;
  10. $sheet = $book->Worksheets(1);
  11.  
  12. // input stuff into excel spreadsheet
  13. for ($i = 0; $i < count($_POST[input]); $i++) {
  14. $cell = $sheet->Cells(1, $i + 1);
  15. $cell->Activate;
  16. $cell->value = $input[$i];
  17. }
  18.  
  19. // run macro
  20. $excel->Run(”runModel”);
  21.  
  22. // save spreadsheet
  23. $book->SaveAs(”model.xls”);
  24.  
  25. // quit Excel and clean up
  26. $book->Close(false);
  27. unset($sheets);
  28. $excel->Workbooks->Close();
  29. unset($book);
  30. $excel->Quit;
  31. unset($excel);
  32.  
  33.  
I modified the above code to suit my code like this

Expand|Select|Wrap|Line Numbers
  1.   $book = $workbook->ActiveWorkbook;
  2.   $sheets = $book->Sheets;
  3.  
  4.   $workbook->Run("TTS_PROJECT_REPORT_MACRO.xls");
  5.   $book->SaveAs($filename.".xls");
  6.   $workbook->close();
  7.  
I avoided calling COM as it is giving error to me.Even then the code is not working.It is giving an error saying RUN is a non-existent function.

Can you please help with this?

Any other suggestions are welcome.

Thanks&Regards,
Shara.


Hello Jenkins,

This is a dynamic report that affects a substantial amount of users.I'll try the proposed.

Thanks for your help.

Regards,
Shara.
Jan 29 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
2
by: saddist | last post by:
Hello, I have and excel sheet with fields: Name | Surname | Dept. When I execute the following code, it imports 16 empty rows + filled ones DoCmd.TransferSpreadsheet acImport = 0,...
12
by: forrestgump | last post by:
I am currently trying to create VBA to send a specified excel sheet to varied email sources. I currently have the code below which sends the attachment in an email to a specified source e.g....
1
by: abdulkarim | last post by:
I have an excel project and I want to protect my spreadsheet for editing by another user except few cells. If it can be possible by using vb code then help me. thanks
1
by: tarekz | last post by:
I have a table on an SQL server 2005, I would like to change the value of one field to another based on an excel sheet value. In other words, if the value in the SQL table matches the value in...
3
kirubagari
by: kirubagari | last post by:
I would like to duplicate the numbers from from excel sheet 1 to excel sheet 2.Kindly help me on this.Sometime its unable to duplicate.. Sub Duplicate Dim oDoc As Object, oSheet As Object,...
1
kirubagari
by: kirubagari | last post by:
Hai experts, How to duplicate the data from 1 excel sheet to another excel sheet 2. Lets say Name Voucher Value Voucher Number lee 300.00 ...
0
by: sadhana86 | last post by:
Hi There, I have a excel sheet which is a report, which I run in a SAP application. Now I have so many fields, below is the example of the report: User_iD Action Info_type Sub_Info_Type ...
0
by: goodamr | last post by:
I'm using this classic ASP code to get the data of the Excel Sheet named Sheet1: Set conn = Server.CreateObject("ADODB.Connection") conn.Provider = "Microsoft.ACE.OLEDB.12.0"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.