Jump to content

Define excel column type upon exporting in php via header


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..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.