1

Need help! I'm just new in php and dont know how to export a data from database to excel.

The excel format must be like this: enter image description here

Can you help me or suggest a function where this format can be make? The Headers like Hit Rate,Production Time, Service Time will be hard coded. The YC Alabang,and all the records under the headers will be coming from database. Thanks!

2
  • Does it have to be Excel or is csv ok? Commented Dec 28, 2016 at 1:20
  • It must be a excel file sir Commented Dec 28, 2016 at 1:24

2 Answers 2

1

You can use PHPExcel library. With this library, you can compose the excel file with any complex of header structure.

PHPExcel Library

Also please check this article on Stackoverflow

How to export data to an excel file using PHPExcel

This link will give you better look on coding style.

Sign up to request clarification or add additional context in comments.

1 Comment

udated link for above library is github.com/PHPOffice/PHPExcel which is archieved and it's successors link is github.com/PHPOffice/PhpSpreadsheet
0

You can also use EasyXLS Excel library. The pic shows me that you need to export an Excel file from database, with the cell from headers merged, borders and gray background.

This link shows you how to export data from database to Excel in PHP. It has a special section on this matter only:
http://www.easyxls.com/manual/FAQ/export-to-excel-in-php-asp.html

This link shows how to set the borders and cell background: http://www.easyxls.com/manual/basics/format-excel-cells.html
like

$xlsStyleHeader->setBackground((int)$COLOR_GRAY);
$xlsStyleHeader->setBorderColors ((int)$COLOR_GRAY, (int)$COLOR_GRAY, 
                                  (int)$COLOR_GRAY, (int)$COLOR_GRAY);
$xlsStyleHeader->setBorderStyles ($BORDER_BORDER_MEDIUM, $BORDER_BORDER_MEDIUM, 
                                  $BORDER_BORDER_MEDIUM, $BORDER_BORDER_MEDIUM);

This links shows you how to merge the cells: http://www.easyxls.com/manual/basics/excel-merge-cells.html like

$xlsTable = $workbook->easy_getSheet("Sheet1")->easy_getExcelTable();
$xlsTable->easy_mergeCells_2("A1:C3");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.