PHPExcel; MySQL中的数组问题

x8diyxa7  于 11个月前  发布在  Mysql
关注(0)|答案(2)|浏览(86)

该网站有多个级别的查看/编辑权限。
我一直在为一个网站的页面工作,该网站收集存储在SQL数据库中的信息并填充Excel模板。
application.php包含所有数据库连接等。
基本上,我遇到的问题是,当我调用数组来填充单元格时,它显示为相同数组值的重复项,不仅如此,它还将它们都塞到同一列中。
我需要填充的值是:
物料编号描述U/价格数量合计
15666562003灯组件$20.00 1 $20.00
运费131514 $12.35 1 $12.35
数据将显示如下:
物料编号描述U/价格数量合计
运费运费131514 131514 $12. 35 $12. 35 1 1 $12. 35 $12. 35

<?php

include "./include/application.php";
require './Classes/PHPExcel.php';

error_reporting(E_ALL ^ E_NOTICE);

class CForm extends CApplication
{

function CForm()
{
$this->CApplication();
}

//**********************************************************

function Export($msg = "")
{

if ($_SESSION['aID'] == "" && $_SESSION['mID'] == "237" && $_SESSION['mID'] == "178" &&        $_SESSION['mID'] == "551")
{
    $sWhere = " AND dID = '$_SESSION[mID]'";
}

$sql = "SELECT * FROM dl_warranty_claims 
        INNER JOIN dealers ON (dID = wDealerID)
        WHERE 1 ".$sWhere." AND wID = '$_GET[id]'";

$res = $this->SQL($sql);
if (!($row = $this->FetchArray($res)))
{
    print "You do not have access to view this report.";
    exit();
}

error_reporting(E_ALL ^ E_NOTICE);
// Read the template file
 $inputFileType = 'Excel2007';
 $inputFileName = './templates/warrantyclaimtemplate2.xlsx';
 $objReader = PHPExcel_IOFactory::createReader($inputFileType);
 $objPHPExcel = $objReader->load($inputFileName);

// Adding data to the template
$objPHPExcel->getActiveSheet()->setCellValue('A3', ($row['wDealerName']));
$objPHPExcel->getActiveSheet()->setCellValue('B3', ($row['wID']));
$objPHPExcel->getActiveSheet()->setCellValue('C3', ($row['wCustomerName']));    
$objPHPExcel->getActiveSheet()->setCellValue('D3', ($row['wModelName']));
$objPHPExcel->getActiveSheet()->setCellValue('E3', ($row['wChassisSN']));
$objPHPExcel->getActiveSheet()->setCellValue('F3', ($row['wEngineSN']));
$objPHPExcel->getActiveSheet()->setCellValue('G3', ($row['wDateDelivery']));
$objPHPExcel->getActiveSheet()->setCellValue('H3', ($row['wDateFailure']));
$objPHPExcel->getActiveSheet()->setCellValue('I3', ($row['wDateClaim']));
$objPHPExcel->getActiveSheet()->setCellValue('J3', ($row['wOperatingHours']));

    $sql = "SELECT * FROM dl_warranty_parts 
            WHERE wpWarrantyClaimID = '$_GET[id]'";
    $res = $this->SQL($sql);
    while($rowp = $this->FetchArray($res))
    {
        $objPHPExcel->getActivesheet()->FromArray($rowp, NULL, 'A4');
    }

// Write and save file
 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

 header('Content-Type: application/vnd.openxmlformats-  officedocument.spreadsheetml.sheet');
 header('Content-Disposition: attachment; filename="warrantyclaimreport.xlsx"');

 $objWriter->save('php://output');
}
}

?>

字符串

4ioopgfo

4ioopgfo1#

您的保存语句

$objWriter->save('WarrantyClaim.xlsx');

字符串
正在将一个名为WarrantyClaim.xlsx的文件写入磁盘(在脚本的当前工作目录中)。
然而你有标题阿英你要把输出发送到浏览器
除了为您正在编写的文件类型发送正确的头文件之外:

Filetype    Writer        Content type    
.xls        Excel5        application/vnd.ms-excel
.xlsx       Excel2007     application/vnd.openxmlformats-officedocument.spreadsheetml.sheet


保存到php://output将把文件发送到浏览器
您的Reader也有类似的问题:在应该使用Excel2007 Reader时,使用Excel5 Reader读取.xlsx文件

798qvoo8

798qvoo82#

对于你的最新问题,你的$this->FetchArray()方法似乎返回枚举关联数据.我不知道参数是什么,但应该有一些设置,允许你指定枚举关联,或一个方法调用,如FetchAssoc(),将专门返回一个关联数组

相关问题