Jump to content

email / excel spreadsheet writer part of previous.


jake2891

Recommended Posts

Hi guys can anyone please help me? I have to run a script that generates a report into an excel document then emails the document simultaneous to the user with the spreadsheet attached! Although it needs to write a document for each users specific details in the database and mail that user his specific spreadsheet with his details in! Heres a sample of what im trying to do. Sorry forgot to mention in the previous post that the part that i cant get working at all is how to mail the document while the scripts runs all that happens now is it open an asks whether i want to save the document. If im going about this all wrong an there is an easier or better way please advise.

 

require_once 'Spreadsheet/Excel/Writer.php';

 

$sql = "select distinct agent from leads";

$qry = mysql_query($sql, $conn);

 

$workbook = new Spreadsheet_Excel_Writer();

 

$workbook->send('liveleads.xls');

 

$worksheet =& $workbook->addWorksheet(liveleads);

 

$worksheet->write(0, 0, 'agent');

$worksheet->write(0, 1, 'leadID'); // all leads for that agent

$worksheet->write(0, 2, 'contactperson'); // all contacts that agent has

 

while($array = mysql_fetch_array($qry)) {

$i = 1;

$sql2 = "select * from leads where agent = $array[agent]";

$qry2 = mysql_query($sql2, $conn);

     

        while($array2 = mysql_fetch_array($qry2)){

              $worksheet->write($i, 0, $array[agent]);

              $worksheet->write($i, 1, $array[leadID]);

              $worksheet->write($i, 2, $array[contactperson]);

              $i++;

 

 

        }

mail($array,"subject"etc.......");

}

$workbook->close();

 

#so basically i need to loop through the agents get the leads that belong to the specific agent

#then write an excel document for each agent listing his specific leads

#then mail each agent with his specific document attached containing his leads while the script runs

 

#Any help will be greatly appreciated :)

Hi sorry about that did not know.

 

The problem is im not sure on how to email the workbook to the end user while the script runs. basically this script is set to run once a week on a monday write up a spreadsheet of data and mail each user his specific speadsheet?

Hi sorry about that did not know.

 

The problem is im not sure on how to email the workbook to the end user while the script runs. basically this script is set to run once a week on a monday write up a spreadsheet of data and mail each user his specific speadsheet?

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.