Jump to content

Recommended Posts

I tried it but no luck.

 

here is the code if it can help:

 

$filename ="excelreport.xls";
$path = 'C:\some\path\here\excelreport.xls';

if(file_exists($path)):	
	$fh = fopen($filename, 'a') or die("can't open file");
	$contents = "name \t companyName \t address \t num \t email \t url \t \n";
	fwrite($fh, $contents);
	fclose($fh);
	echo 'file exist';
else:

	echo 'does not exist';
endif;

Well, excel doesn't do tab delimited formats in an XLS file. Are you using the XLS format? XLSX? What version of Excel would you like to write to?

 

I suggest opening the Excel file with a text editor to see how it's formatted, or use a standard that excel supports like CSV.

Never mind, there's probably tons of binary data for you to decode.

 

Why not format your files in CSV rather than using Excel formats? Excel can read CSV files without issue.

 

Otherwise, you could try

http://phpexcel.codeplex.com/ - This is for Excel 2007 though.

Unless you're ready to learn the Excel document format and it's intricacies, you're kinda S.O.L. :(

 

You can't just 'append' to the end of an excel file... you have to find out where the last cell of information is so you can start creating new cells below it.

 

Again, I think you should just use the CSV format. Excel can open those fine. Here's an example of a CSV file

http://seepeoplesoftware.com/downloads/older-versions/11-sample-csv-file-of-us-presidents.html

 

Very easy to append information on the end, and very easy to manipulate.

i got it actually. :)

using this:

$filename ='C:\some\path\excelreport.xls';
$path = 'C:\some\path\excelreport.xls';

if(file_exists($path)):
	$fh = fopen($filename, "a") or die("can't open file");
	$contents = "name \t companyName \t address \t num \t email \t url \t \n";
	fwrite($fh, $contents);
	fclose($fh);
	echo 'file exist';
else:

	echo 'does not exist';
endif;

 

but i'm having trouble on this one:

$filename ="excelreport.xls";
$path =  'C:\some\path\excelreport.xls';

if(file_exists($path)) {

	$filepath = 'C:\some\path\excelreport.xls';
	$fh = fopen($filepath, "a") or die("can't open file");
	$write = "$name \t $companyName \t $address \t $num \t $email \t $url \t \n";
	fwrite($fh, $write);
	fclose($fh);
	exit;

} else {

	$contents = "NAME \t COMPANY NAME \t ADDRESS \t PHONE NUMBER \t EMAIL \t URL \t \n";
	$contents .= "$name \t $companyName \t $address \t $num \t $email \t $url \t \n";
	header("Pragma: public");
	header("Expires: 0");
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	header("Content-Type: application/force-download");
	header("Content-Type: application/octet-stream");
	header("Content-Type: application/download");
	header('Content-type: application/vnd.ms-excel');
	header("Content-Disposition: attachment;filename=".$filename);
	header("Content-Transfer-Encoding: binary ");
	echo $contents;

}

 

 

it executes the else statement even though the file exist.

any ideas?

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.