I have an excel spreadsheet that contains some formulas to calculate ROI for an upcoming product of a client. Is it possible to convert this into a php script whereby a user would type into some boxes and then submit it working out the same. The excel spreadsheet is here: http://www.solidcamxpress.co.uk/roi.xls
Sure, PHP can do math just like Excel's formulas. However, there is no magic method of converting Excel to a Web page, if that's what you're asking.
#Cameron
There is a software in the market which can convert the spreadsheet to active html/php with ease. You can get the software at the following url:
http://www.spreadsheetconverter.com
Even you can also convert the spreadsheet by yourself as it is simple to convert with scripts. but you can also this software for the conversion =)
You can use PHPExcel to read an existing spreadsheet and extract its data/formulas, but converting those formulas from Excel syntax to PHP is rather non-trivial.
Unless you're doing a generalized Excel->PHP converter, the time/effort required to write such a converter will be far greater than it would take you do analyze the one spreadsheet by hand and code up some PHP stuff to recreate it.
Related
I have written some PHP that uses a simple HTML form to take in an ISBN number, uses that number to search Amazon's database, gets the book title and pricing information and then exports the information to notepad.
What I need to do now is change it so that a large number of ISBN's can be searched automatically. I was thinking I could do it either by having an excel sheet of ISBN's that I upload, or copy and pasting all of the ISBN's at once into a form.
I need some guidance on how to do this. I do not have a lot of PHP experience.
Thanks!
Here's a PHP library I use for my Excel needs: PHPExcel
It comes with good examples and documentation to get you started.
I'm using PHPExcel for transferring data between MySQL DB and Excel 2007 worksheets. It works well on most situations, but I encountered one problem.
Some of the fields in DB contain HTML data. I need to preserve the formatting in Excel cells as much as possible. As I could figure out, Excel allows the following formatting inside cells (PHPExcel_RichText class supports all of these): new lines [these can be used to track <p></p> blocks], font name, size, color, bold, italic, underline, strikethrough, subscript, superscript. Suppose these are enough, so we can ignore other HTML formatting.
What is the best (easiest, fastest) way to convert HTML data to Excel Rich Text and vice versa?
One solution I've in mind is to create a function that will traverse the HTML [using DOMDocument or so], place \n after block elements, create PHPExcel_RichText_Run objects for <b>, <i> etc, and ignore all other elements. I feel this will be quite "expensive", especially when dealing with nested structures, like <b>some <i>formatted<i> text</b>
Is there any better way to do this, with or without PHPExcel?
One more idea: I noticed that when exporting in XML Spreadsheet 2003 format the following appears inside XML:
<ss:Data ss:Type="String"
xmlns="http://www.w3.org/TR/REC-html40"><Font html:Color="#000000">this is </Font><B><Font
html:Color="#000000">some </Font><I><Font html:Color="#000000">formatted</Font></I><Font
html:Color="#000000"> text</Font></B></ss:Data>
which is normal HTML4. I mean it seems that Excel can understand plain HTML. So maybe there is some way to pass HTML directly to Excel without converting it to PHPExcel_RichText objects... (although note that it would be best if I'll be able to export to .xlsx format)
HTML to Rich-Text Runs is on the PHPExcel development roadmap for the coming year: however, the planned method was to use DOMDocument to parse the markup.
Any solution that we adopt for PHPExcel itself will have to use RichText Runs to provide consistency. While MS Excel itself can handle direct imports of Excel, and (as you've noted in the SpreadSheetML xml format offered by Excel 2003), this isn't consistent across the other different Excel formats (BIFF and OfficeOpenXML).
Let's say I've some data in cells A1-Ax from which I should get this data, process and write the result to the B1-Bx, C1-Cx and D1-Dx cells. Preferably using PHP.
You may want to look at PHPExcel.
(PHPExcel) provides a set of classes
for the PHP programming language,
which allow you to write to and read
from different file formats, like
Excel 2007, PDF, HTML, ... This
project is built around Microsoft's
OpenXML standard and PHP.
I think this is best when you have a large application written in PHP which handles excel files. I think this is not the best for very small changes.
Hope that helps.
PHPExcel is really good for reading/writing excel documents (and csv files).
Used it in a lot of projects, works really well.
Let's go ahead and get this out of the way - i realize I can generate tables with php and mysql and output in 'almost' any format I need but in this scenario, the excel spreadsheet is formatted in some strange ways (layout, color, etc) and the client won't budge. I have to use the exact excel spreadsheet.
I am trying to pull data from a mysql database with php calculations behind it and populate various cells within an Excel file. Is it possible to do this?
Thank you ahead of time
You can try PHPExcel ( http://phpexcel.codeplex.com/). I think this is what you are looking for.
I have tabulated data in an Excel spreadsheet (file size will likely never be larger than 1 mb). I want to use PHP to parse the data and insert in to a MySQL database.
Is there any advantage to keeping the file as an .xls/.xlsx and parsing it using a PHP Excel Parsing Library? If so, what are some good libraries to use?
Obviuously, I can save the .xls/.xlsx as a CSV and handle the file that way.
Thanks!
If you are just after the values, I would save it as a CSV. This is much easier to parse programatically, especially if you are trying to do this on a non-windows box.
That being said, there will be information lost in the export to CSV. It will only save the values of the cells - not their formatting information, formulas, etc. If you need to use that information, you're better off doing this straight from Excel.
Here is a PHP Excel Reading library. If you decide to read Excel files directly, this may help get you started.
If your excel files contain strictly data and contain no formulas, scripts, macros and etc., I would say parsing through Excel will only add development overhead, and will potentially slow down processing. It would probably be best to convert the files to CSV in this case.
Also consider that MySQL's 'LOAD DATA INFILE' command can be used to import entire CSV files into a table, this can potentially further uncomplicate matters for you.
when you provide a way for customers to upload excel/csv files, you should consider that
CSV files will only export one sheet
Having multiline cells will make the CSV parsing complicated
You cannot easily detect corrupted/incomplete CSV files
CSV files do not include formatting
Besides from that, importing CSV is a lot easier than importing XLS.
Remember that if you're importing the csv file directly into Mysql, that you may have problems with the date format (as Mysql uses a different date format to Excel). I find it easier to change the date fields in Excel first (to format yyyy-mm-dd) prior to saving as a csv file.
Edit: Although I've not used it myself, others have recommended Navicat as a very good tool for converting Excel spreadsheets or Access data into Mysql databases. May be worth a look.
With Office 2003 there's an XML format called SpreadsheetML which is a bit in-between XML and Excel. I've considered using this format to import/export data to a web site but the format turns out to be a bit complex. Internally, this format turns all references into relative references. (Relative from the current location.) Worse, some cells have an index, thus you might see a row with only two cells, but the second cell might be 6 columns away from the first cell. (In which case Index=5.) Basically, if you want to use the Excel format, you will need to have a good way to calculate the position of each cell and know how to translate the references in the cells in a proper way.
If you're onlyinterested in the data, CSV would be much, much easier to implement. As an in-between solution, you could define an XML schema and add an XML mapping to your spreadsheet to export the data to an XML file. It's more complex than CSV i9mport/export, but also a bit more robust. But the Excel or Excel XML formats themselves are horrible to implement. (Or just a nice challenge, if you're a real XML expert.)