I'm using code from http://forums.codeguru.com/archive/index.php/t-470940.html to create excel in php. Is there a way to add styles like bold and/or italic to cells when doing it that way? Thank you
The method shown in that thread does not generate an Excel .xls file. It generates a tab-separated-value file. This is a plain text format, that does not support styling of any kind
If you want to generate a real xls file with formatting, then look at some of the libraries that can be used from PHP to write actual Excel files such as my PHPExcel library
EDIT
In addition to PHPExcel, you can find details of other PHP libraries for writing real Excel files in the answer to this question
Related
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.
My application is fetching a data dynamically from MYSQL and displaying. The Problem is even i have to give the option to "Export to Xls" file. And these file should be in a A4 size, so i should customize the font size of contents in the Xls file to fit into the A4 size.And i need to insert if possible image into the file.
Please help me to solve this as i am new to php and need to complete it within a day.
You can use
PHPexcel or
PEAR_Spreadsheet_Writer
php_excel extension by Ilia Alshanetsky (this requires a commercial license for libXL)
to create the Excel Sheets.
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
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
I am echoing TSV data and turning it into an excel file via header()
This works fine, but 1 of the columns needs to be an image. How can I embed the image as one of the columns?
Thanks!
Well, put simply, you can't. A TSV is a plain text (text/plain) file, not an 'Excel file'. An excel file is a binary representation of a spreadsheet, and although Excel can read a TSV and present it as tabular data, it's not this advanced binary form which can contain images.
You would have to create a 'proper' Excel xls file using one of the available libraries. I've used PHPExcel in the past and I think it supports adding images.
I don't believe there is anyway to use TSV data, and get Excel to display an image.
However, I have had success in using Spreadsheet_Excel_Writer from PEAR, and it supports inserting images (bitmaps). Also supports nice formatting, etc, etc.