View Full Version : Working with XLS spreadsheets in PHP
I'm working with someone who has a 'broken' xls file....
For whatever reason some data just refuses to act like numerical data... I'm sure someone can tell me an excel fix (and I'd be glad to hear it) but I was thinking it would be cool if I could load the data into PHP, hack on it and make a new xls file... Only problem is... I have no idea how.... I'm mostly interested in how to write a xls file as I can load the original data from a CSV file or something.
Thx in advance...
Dave
Ask and ye shall receive:
Write out your data TAB delimited with a \n at the end of each line, save it to a file named /tmp/$fn . If you have trouble with file_put_contents just write your own file_put_contents function that creates a file, writes $lines to it and closes the file. I've tested this in many Browsers and it works perfectly.
<?php
if(file_put_contents("/tmp/$fn",$lines)){
ob_clean();
$f = str_replace(' ','_',$_POST['filename']) . "_report.xls";
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$f);
header( "Pragma: " );
header( "Cache-Control:" );
readfile("/tmp/$fn");
unlink("/tmp/$fn");
exit;
}
?>
Before I ask a bunch of stupid questions (which I'll still probably do)... I'm going to try it.
-- Dave
Count to 10 before asking any questions! ;)
zlatan24
11-22-2007, 08:33 AM
There is a not bad tool, try it - fix xls (http://www.recoverytoolbox.com/fix_xlsx.html), work with variety of causes, such as HDD corruption, download errors, viruses, hardware failure, that can lead to Excel file corruption, file is analyzed, you can see the results in a preview window and fix corrupted xlsx files, your recovered data is not formatted, you can only preview your document, not fix corrupted xlsx, also will save many hours of your work and help to fix corrupted xlsx files.
Hi,
If necessary, you may try Advanced Excel Repair at http://www.datanumen.com/aer/ This tool is rather useful in salvaging damaged Excel xls files.
Alan
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.