Convert .xls file to xml using php - php

I need to implement a functionality where a user can upload an Excel file, that is, .xls file and i need to write a function that will read that file and then save the values in a table, compare them to values in another table and then print some kind of billing quotation.
From what I have read, it seems that the best way to do that is to first convert that file to an xml file and then write a function to parse that xml file.
I want to know, is it possible to write a function in php that will convert an xls file to xml. Assuming that the users will save and upload the file as xls.
Thanks.

i often let admin users upload a csv file they exported from an xcel file, its much simpler to parse through using http://php.net/manual/en/function.fgetcsv.php

A quick Google search for "PHP excel parser" turns up PHP Excel Reader, for an open source library to use for reading data from .xls files. There may be others that suit your needs.

I have been successfully using the 'ABC Excel Parser Pro' from Zakkis.
This allows converting from a XLS file directly into a MySQL table.
A few notes on limitations:
column count must match exactly to database columns
Excel 2007 format (xlsx) are not supported

Related

format .csv data created with fputcsv into Excel-like tables

is there a way that I can format data from a .csv file created with the php function fputcsv into Excel-like tables? Meaning, I don't want my data to be separated by commas, I want them to appear in tables like an Excel spreadsheet or something.
I know I can do that in Excel itself, but is there a way to do that directly without tweaking the file in Excel (like with a php function or something)
fputcsv does exactly what the manual says:
It formats a line as CSV and writes it to a file pointer.
The output can then be imported into Excel or other csv-capable software.
You can generate Excel files directly via php, too, but therefore you have to delve very deep into the Excel file format. If you want to do this, I recommend PHPExcel. This project 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.

Export to CSV with customizing the font color using PHP

In my application i am able to export data to CSV file successfully, But i need some contents of the CSV file to be in "bold" and "color".
So is it possible way to do it? If so please help me out.
If it is a valid option, you can export to Excel format using PHPExcel. This supports font color, weight etc..
The basic CSV file format doesn't have any way to represent such attributes. If the file is to be read by a specific application, maybe it supports a richer format that you can output in?
As others have said, you can not do it with CSV. But if your target program to read the CSV is Excel, you can create a XLS spreadsheet.
But I have had very good success using Spreadsheet_Excel_Writer: http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.php
Give it a shot.
CSV file is just comma separated values file so it can't be formatted. this is a simple text file with .csv extension. If you want to format then exporting into excel.

How can i take an excel file, parse it contents and store the column's data of excel sheet in my database column?

There is one excel sheet which contains student name, rollno etc. How can i parse the contents of excel file and store that in my sql database?
You are looking for PHPExcel library i believe.
http://phpexcel.codeplex.com/
use this class to read the excel files
http://sourceforge.net/projects/phpexcelreader
If you want to do it directly from the Excel file, rather than create an intermediate CSV using Excel's "Save As" options, then look at libraries such as PHPExcel that can read the xls binary format and make the data accessible to your PHP script.
I'd recommend to you that you save it as csv, it's much more easier and less hacking to upload it to the database
here is simple a sample
http://www.bradino.com/php/csv-upload-to-database/
PHPExcel is one of the best PHP classes i have ever worked with. In addition to parsing and reading files of all Excel variations (including csv) the output to Excel 2007 + is excellent.
Be sure to look at the documentation and examples...they will get you up to speed very quickly

Automate converting excel xls file to excel xml

I have a web page where a user can upload xls files. When he uploads a file, i want to automate converting the excel file to excel xml. I want to convert it to an xml file as i think it will be easy to handle the data.
Is it possible to write my own php function to do that?
Let me see if I understand. You're going to read a XLS file, write it out as XLSX, then read in the XLSX?
Why not just deal with the XLS in the first place?

Php code to convert .xml to .xls(Basically from xmlExcel to Excel spreadsheet)

Is there a way to convert .xml file to .xls using php code?
1) Read in the XML file using [simplexml_load_file()][1]
2) Loop through each XML element representing one line item in the XLS file
3) Use [fputcsv()][2] to create a comma separated file with the data from step 2
4) Save the file with a .csv extension and it will open in excel.
If you want to create an Excel spreadsheet I think you need to work with COM objects. Not my forté so I can't help you with that.
Dunno about converting XML to XSL, but in the book PHP Hacks there is a hack for generating excel spreadsheets most of which is available on Google Books, in its chapter on XML no less!
So that would be a good place to start looking if nobody's got the answer here.

Categories