Export to xls in customised way - php

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.

Related

Is there any way to change the font size for Chart title, Legend and the data label?

Is there any way to change the font size for Chart title, Legend and the data label?
The problem facing is our team are using the library "phpspreadsheet"(link to library github) to generate some excel files with chart and find out the font size of the chart title, the data legend and the data label is too small.
(please see screenshot attached.)
The screenshot for the report
I have searched the documentation and sample from the library but seems there is none mentioned how to change it.
Thanks all if there is any suggestion on this.
So the thing is, that XLSX files are zipped XML files.
What the PhpSpreadsheet is doing, is using pre-made XML templates to fill it with the data you would like to see on the XLSX, then zip the whole stuff, and name it XLSX.
If you wanna change the font size, then you have to find the right place in the used template. Luckily the PhpSpreadsheet provides a lot of samples in the phpoffice\phpspreadsheet\samples\Chart folder. If you execute the 32_Chart_read_write.php, it will create 1 file from each template and gives you the paths.
The templates are located here: phpoffice\phpspreadsheet\samples\templates
If you unzip it you will see 3 folders filled with XML files. The one which responsible for the styles is most likely the xl\styles.xml file. The size should be in a tag and it's also a tag with a name of sz. For example:
<sz val="23.5"/>
Here you modify the size of the font, then zip it back to XLSX and save it wherever you want and use it as it is provided in the samples.

PHP export to excel with styles

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

Adding Macro on Excel XML-specification to generate a native

I'm exporting data in excel sheet via drupal view. Drupal views_export_xls module uses
http://code.google.com/p/php-excel/source/browse/branches/class-excel-xml.inc.php?r=9
library to export data into excel sheet. Every thing working fine. But i want little more from it.
How to add MACRO in excel sheet row or cell programmatically?
Is it possible to do so by php code?
If you look at above link - line no 88 & 93 which actually create cells and rows.
What i want to create a macro and place it on excel sheet that can later convert this generated excel file into native xml (.in) file for business purpose.
I've searched a lot but most of the link suggesting VB solution and i've no sense about this language.
Can anyone point me on right direction.
Any help would be greatly appreciated!
As far as I'm aware, unless the Excel writer that you're using is based around COM, then there is no way of creating a Macro in an Excel workbook.

PHPExcel feature question

I want to know if PHPExcel can:
Create Excel spreadsheets with embeded image. The image must be compressed (jpeg, png, gif...).
Create Excel spreadsheets for different Excel versions (2000, 2003, 2007...).
I'm pretty sure it can do this but I can't find it in the official docs.
Anyone familiar with this class can help?
Thanks!
Yep. It works great for all of the above. If you download the latest version there are docs in the Documentation/PHPExcel developer documentation.doc
Section 4.4.38 pg 26 shows how to add a GD drawing to a sheet.
Section 6.2.2 pg31 shows how to export in Excel 2007 format. Subsequent pages show other excel versions, and there is a useful set of tips on getting the right headers etc to make the .xls downloadable.
PS let me know if you need sample code... will post it here.

Create a multi-tabs Excel file

My PHP script have to create a multi-tabs Excel file with a report in each tab, but those reports already exists as HTML pages, so I don't want to duplicate code and work.
I know I can rename a HTML file to .xls, and Excel/OpenOffice Calc will open it as a spreadsheet, but I don't know how to have severals tabs.
I do not even know if it is possible.
I already know Biffwriter and others PHP libs to create Excel file, but I am looking for a smarter solution.
Thanks,
Cédric
Pear Excel Spreadsheet Writer has a function to create new Worksheets if thats what you are looking for.
If you don't mind serving excel 2007 files, you can do this:
create an excel 2007 file
create all the tabs you need
save the file
rename the file as .zip
extract the contents of the zip file
Now you can use the file structure there to populate the file corresponding to each tab with the report you need. You may want to use them as templates, keep the same code and render different files depending on whether you generate the html report of the excel report.
In the end, zip up the entire directory structure and serve it with an xlsx extension.
Please check the URLS of
a library
and
turorials
from IBM and
from 999Tutorials

Categories