harchew Posted January 14, 2008 Share Posted January 14, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/85912-define-excel-column-type-upon-exporting-in-php-via-header/ Share on other sites More sharing options...
btherl Posted January 14, 2008 Share Posted January 14, 2008 How do you create the excel data? Quote Link to comment https://forums.phpfreaks.com/topic/85912-define-excel-column-type-upon-exporting-in-php-via-header/#findComment-438639 Share on other sites More sharing options...
harchew Posted January 14, 2008 Author Share Posted January 14, 2008 <?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> Quote Link to comment https://forums.phpfreaks.com/topic/85912-define-excel-column-type-upon-exporting-in-php-via-header/#findComment-438645 Share on other sites More sharing options...
sasa Posted January 14, 2008 Share Posted January 14, 2008 look http://www.phpfreaks.com/forums/index.php/topic,155530.0.html Quote Link to comment https://forums.phpfreaks.com/topic/85912-define-excel-column-type-upon-exporting-in-php-via-header/#findComment-438896 Share on other sites More sharing options...
roshanbh Posted January 14, 2008 Share Posted January 14, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/85912-define-excel-column-type-upon-exporting-in-php-via-header/#findComment-438954 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.