2012-08-01 60 views
0
//to genrate EXCEL files 
require_once('documentation/Excel_Writer/Writer.php'); 
    if($_POST['submit'] == "Email as EXCEL"){ 


    // get values 

     $dated1=$res_hist[0]['dated']; 
     $subject1=$res_hist[0]['businesscategory']; 
     $hisstartdate=$dateto; 
     $hisenddate=$datefrom; 

    //format of date// 
     $date = $hisstartdate; 
        $history= date( "j F Y", strtotime($date)); 
        $date1 = $hisenddate; 
        $history1= date( "j F Y", strtotime($date1)); 
     //print_r($date);die;   

     $path="businesshistoryxls/"; 


      $workbook = new Spreadsheet_Excel_Writer(); 
      //print_r($workbook);die; 
      $format_bold =& $workbook->addFormat(); 
      $format_normal =& $workbook->addFormat(); 
      $format_bold->setBold(1); 
      $format_normal->setBold(0); 
      $worksheet =& $workbook->addWorksheet(); 


      $worksheet->write(0, 0, "TransactionID", $format_bold); 
      $worksheet->write(0, 1, "Date", $format_bold); 
      $worksheet->write(0, 2, "Type", $format_bold); 
      $worksheet->write(0, 3, "Transaction Details", $format_bold); 
      $worksheet->write(0, 4, "Currency", $format_bold); 
      $worksheet->write(0, 5, "Amount", $format_bold); 
      $worksheet->write(0, 6, "Balance", $format_bold); 



      $sqlza = "Select * from BUSINESSTRANSACTION where isACTIVE=1 and BusinessID=".$_SESSION['businessID']." order by dated DESC";  
      $resza = getXbyY($sqlza, "array"); 
      $rowsza = count($resza); 
      // print_r($resza);die; 
      if($rowsza>0) 
      { 
      for($i=0;$i<$rowsza;$i++) 
       { 
        $worksheet->write($i+1, 0, $resza[$i]['transactionID'], $format_bold); 
        $worksheet->write($i+1, 1, $resza[$i]['dated'], $format_bold); 
        $worksheet->write($i+1, 2, $resza[$i]['transactionTYPE'], $format_bold); 
        $worksheet->write($i+1, 3, $resza[$i]['transactionDETAILS'], $format_bold); 
        $worksheet->write($i+1, 4, $resza[$i]['currency'], $format_bold); 
        $worksheet->write($i+1, 5, $resza[$i]['amount'], $format_bold); 
        $worksheet->write($i+1, 6, $resza[$i]['balance'], $format_bold); 



       } 
       } 

     $workbook->send($xlsname); 
     $type=".xls"; 
     $xlsname=$path.''.$hisstartdate.''.to.''.$hisenddate.''.$type; 


    $email_to = $res_pers[0]['email']; 
    //print_r($xlsname);die; 
    $email_from="[email protected]"; 
    $email_subject = "Transactions's History"; 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    $headers.= 'From:'.$email_from."\r\n"; 
    $email_message="Dear ".$username."<br><br>"; 
    $email_message.="Please check the attachment.<br>"; 
    $email_message .="<br/>"; 
    $email_message .=""; 
    $my_path =$_SERVER['DOCUMENT_ROOT']."/".$xlsname; 
    //print_r($my_path);die; 
    mail_attachment($email_from, $email_to, $email_subject, $email_message ,$my_path); 
    //print_r($mail_attachment);die; 
    unlink($xlsname); 
    $msgID=67; 

      $workbook->close(); 
    unset($_SESSION['Historyb']); 
    } 

有人可以帮助我吗?这是我的代码来gererate和电子邮件Excel表,但是当一个电子邮件。我打开附件的Excel表单提示消息,无法读取文件。文件是仅被发送0KB ..作为附件生成并发送excel文件 - 错误信息:无法读取文件

+0

请提及Excel类链接。 – diEcho 2012-08-01 06:45:03

+0

错误地我没有提及..现在你有这个解决方案...? – Nav 2012-08-01 07:26:25

回答

1

1)我已经修改乌尔一段代码,尝试使用此

 $worksheet->write(0, 0, "TransactionID"); 
     $worksheet->write(1, 0, $format_bold); 
     $worksheet->write(0, 1, "Date"); 
     $worksheet->write(1, 1,$format_bold); 
     $worksheet->write(0, 2, "Type"); 
     $worksheet->write(1, 2, $format_bold); 
     $worksheet->write(0, 3, "Transaction Details"); 
     $worksheet->write(1, 3, $format_bold); 
     $worksheet->write(0, 4, "Currency"); 
     $worksheet->write(1, 4, $format_bold); 
     $worksheet->write(0, 5, "Amount"); 
     $worksheet->write(1, 5, $format_bold); 
     $worksheet->write(0, 6, "Balance"); 
     $worksheet->write(1, 6, $format_bold); 

而且根据上面的代码修改代码内部for循环。

2)“$ worksheet = & $ workbook-> addWorksheet();”

添加一些名字你workbooksheet

e.g $工作簿=新Spreadsheet_Excel_Writer($ excelfillename);