Codeigniter编写excel文件

时间:2014-12-07 15:13:12

标签: php codeigniter export-to-excel

我有以下视图文件

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<table border="1" align="center">
    <thead>
        <tr>
                <th>TransactionDate</th>
                <th>SettlementRefNo</th>
                <th>TransactionRefNo</th>
                <th>CustomerName</th>
                <th>TransactionAmount</th>
                <th>TDR</th>
                <th>ServiceTax</th>
                <th>FinalSettledAmount</th>
                <th>MerchantName</th>
           </tr>
    </thead>
    <tbody>
            <?php foreach ($success as $row): ?>
            <tr>
                <td><?php echo $row['trans_date'];?></td>
                <td><?php echo $row['settlement_refNo'];?></td>
                <td><?php echo $row['shmart_refID'];?></td>
                <td><?php echo $row['customer_name'];?></td>
                <td><?php echo $row['trans_amount'];?></td>
                <td><?php echo $row['tdr_amount'];?></td>
                <td><?php echo $row['serviceTax_amount'];?></td>
                <td><?php echo $row['final_settled_amount'];?></td>
                <td><?php echo $row['username'];?></td>
            </tr>
            <?php endforeach; ?>
    </tbody>
</table>
</body>
</html>

这是控制器

        $settlement_processed_data['success'] = $this->report_generation_model->get_processed_data();       
        $myFile = FCPATH."admin_process_settlement_files/".date('d-M-Y').".xls";        
        $stringTransData = $this->parser->parse('settlement_processed_xls', $settlement_processed_data, true);
        $fh = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, $stringTransData);
        fclose($fh);
        $data = file_get_contents("/var/www/html/testingserv/admin/admin_process_settlement_files/".date('d-M-Y').".xls");
        $name="settlements.xls";
        force_download($name, $data);
        unlink($myFile);

控制器的作用是,从数据库中获取数组,并将其加载到视图中并解析内容,但已传递的内容具有

���������������� ���������������� ���������������� ���������������� ���������������� ���������������� ���������������� ���������������� ���������������� ����������� ���� ��������  ����

生成的xls文件位于excel文件的中间。为什么会发生这种情况?

0 个答案:

没有答案