Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php export to excel not showing gridlines

Tags:

php

excel

I have this code

<?php
header("Content-type: application/vnd.ms-excel; name='excel'");

header("Content-Disposition: filename=export.xls");
// Fix for crappy IE bug in download.
header("Pragma: ");
header("Cache-Control: ");
echo $_REQUEST['datatodisplay'];
?>

It puts the data from a html table into excel, but the only problem is that i don`t see the gridline in the sheet. Am i missing something? Thanks

like image 423
gogu Avatar asked Mar 29 '12 18:03

gogu


People also ask

Why won't my gridlines show in Excel?

Select the worksheet. Click the Page Layout tab. To show gridlines: Under Gridlines, select the View check box. To hide gridlines: Under Gridlines, clear the View check box.

How do I export data from PHP to Excel?

Export Data from Database:$fileName – Define the name of the excel file to be downloaded. $fields – Define the column named of the excel sheet. $excelData – Add the first row to the excel sheet as a column name. Fetch member's data from the database and add to the row of the excel sheet.


2 Answers

Today i run into same issue as OP did.

I found @Jayant Pandey answer to be really close to my needs! But issue was that grid border was bigger that header border so instead of 1px i used 0.1pt

Example:

<!DOCTYPE html>
<html>
<body style="border: 0.1pt solid #ccc"> 
   <--! SOME EXCEL CONTENT HERE -->
</body>
</html>

I do know this is an old question but maybe someone is looking for this!

like image 200
Ingus Avatar answered Oct 20 '22 00:10

Ingus


Make sure you DO NOT have a "background-color" attribute defined for your HTML <BODY> tag. That was my problem. Remove it and all the gridlines will magically re-appear in Excel.

like image 37
Aaron McMahon Avatar answered Oct 19 '22 23:10

Aaron McMahon