Jump to content

Define excel column type upon exporting in php via header


harchew

Recommended Posts

I'm using the code below to export all data to an excel.

 

header("Content-type: application/vnd-ms-excel");

header("Content-Disposition: attachment; filename=sales_report.xls");

 

However some of data beings with zero and excel will auto remove it from the column. So is that anyway I can configure the header to define the column type as text. or any solution out there can actually prevent excel form removing zeros. FYI by default the column is set as  general.

<?php

header("Content-type: application/vnd-ms-excel");

header("Content-Disposition: attachment; filename=sales_report.xls");

?>

 

<?php

$result = mysql_query("Select * from Subscriptions order by issue_code,attn");

?>

    <table>

    <tr align="left">

<th>Attn</th>

<th>Language</th>

<th>Company</th>

<th>Address L1</th>

<th>Address L2</th>

<th>Country</th>

<th>Postal</th>

        <th>Issue Start</th>

        <th>Issue End</th>

<th>PnL Code</th>

    </tr>

    <?php while ($row = mysql_fetch_array($result)): ?>

    <tr>

        <td><?php echo $row['attn']; ?></td>

        <td><?php echo $language; ?></td>

<td><?php

$result2 = mysql_query("Select * from subscribers where id = $row[subscriber_id]");

$row2 = mysql_fetch_array($result2);

echo $row2['company'];

?></td>

<td><?php echo $row['address1']; ?></td>

<td><?php echo $row['address2']; ?></td>

<td><?php echo $row['country']; ?></td>

<td><?php echo $row['postal']; ?></td>

        <td><?php echo $row['issue_start']; ?></td>

<td><?php echo $issue_end; ?></td>

<td nowrap><?php echo $row['mag_code'] . ' / ' . $row['issue_code'] . ' / ' . $row['id'];?></td>

 

    </tr>

    <?php

}

endwhile; ?>

 

</table>

hey bro i've posted a really simple class to export the data to excel from database in http://roshanbh.com.np

check out the link below..

 

http://roshanbh.com.np/2007/12/a-simple-class-to-export-data-to-excel-using-php.html

 

I think this might will help you..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.