Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将下拉列表添加到PHPExcel_Php_Codeigniter_Phpexcel - Fatal编程技术网

将下拉列表添加到PHPExcel

将下拉列表添加到PHPExcel,php,codeigniter,phpexcel,Php,Codeigniter,Phpexcel,我想在导出excel模板功能中添加下拉列表 我试图添加这些代码行,但它显示错误 严重性:警告 消息:遇到非数字值 文件名:Excel5/sheet.php 这是我的控制器功能 public function import_export_excel($token){ $this->load->library('excel'); $this->excel->setActiveSheetIndex(0); $this->excel->get

我想在导出excel模板功能中添加下拉列表

我试图添加这些代码行,但它显示错误

严重性:警告

消息:遇到非数字值

文件名:Excel5/sheet.php

这是我的控制器功能

public function import_export_excel($token){

    $this->load->library('excel');
    $this->excel->setActiveSheetIndex(0);
    $this->excel->getActiveSheet()->setTitle('Inventory Data');


    $arr_row = array('Item Code *', 'Item Name * ', 'Barcode', 'Category *', 'Unit of Measurement *', 'Other Information', 'Reorder Point', 'Reorder Value', 'GL Account *', 'Price Category *', 'Price *', 'Supplier *', 'Supplier Unit of Measurement *', 'Cost *', 'Quantity Unit of Measurement *');
    $arr_cell = array('A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1', 'K1', 'L1', 'M1', 'N1', 'O1');
    $arr_dimension = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O');

    for($x = 0; $x < count($arr_row); $x++){
        $this->excel->getActiveSheet()->setCellValue($arr_cell[$x], $arr_row[$x]);
        $this->excel->getActiveSheet()->getStyle($arr_cell[$x])->getFont()->setSize(10);
        $this->excel->getActiveSheet()->getColumnDimension($arr_dimension[$x])->setWidth(30);
        $this->excel->getActiveSheet()->getStyle($arr_cell[$x])->getFont()->setBold(true);
        $this->excel->getActiveSheet()->getStyle($arr_cell[$x])->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    }


    $filename='inventory_data.xls'; 
    header('Content-Type: application/vnd.ms-excel'); 
    header('Content-Disposition: attachment;filename="'.$filename.'"'); 
    header('Cache-Control: max-age=0'); 

    $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
    $objWriter->save('php://output');
}
公共函数导入导出excel($token){
$this->load->library('excel');
$this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->setTitle(“库存数据”);
$arr_row=array(‘项目代码*’、‘项目名称*’、‘条形码’、‘类别*’、‘计量单位*’、‘其他信息’、‘再订购点’、‘再订购值’、‘总账账户*’、‘价格类别*’、‘价格*’、‘供应商*’、‘供应商计量单位*’、‘成本*’、‘数量计量单位*’);
$arr_cell=数组('A1','B1','C1','D1','E1','F1','G1','H1','I1','J1','K1','L1','M1','N1','O1');
$arr_dimension=数组('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O');
对于($x=0;$xexcel->getActiveSheet()->setCellValue($arr_单元格[$x],$arr_行[$x]);
$this->excel->getActiveSheet()->getStyle($arr_cell[$x])->getFont()->setSize(10);
$this->excel->getActiveSheet()->getColumnDimension($arr_dimension[$x])->setWidth(30);
$this->excel->getActiveSheet()->getStyle($arr\u cell[$x])->getFont()->setBold(true);
$this->excel->getActiveSheet()->getStyle($arr\u cell[$x])->getAlignment()->setHorizontal(PHPExcel\u Style\u Alignment::HORIZONTAL\u CENTER);
}
$filename='inventory_data.xls';
标题('Content-Type:application/vnd.ms-excel');
标题('Content-Disposition:attachment;filename=“.”.$filename.'”);
标头('Cache-Control:max age=0');
$objWriter=PHPExcel_IOFactory::createWriter($this->excel,'Excel5');
$objWriter->save('php://output');
}

在excel工作表中输入下拉列表

$items = array ('one, two, three', 'four, five, six');
    for($x = 0; $x < count($arr_row); $x++){

                $objValidation1 = $this->excel->getActiveSheet()->getCell('C'.$arr_cell[$x].'')->getDataValidation();
                $objValidation1->setType( PHPExcel_Cell_DataValidation::TYPE_LIST );
                $objValidation1->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION );
                $objValidation1->setAllowBlank(false);
                $objValidation1->setShowInputMessage(true);
                $objValidation1->setShowErrorMessage(true);
                $objValidation1->setShowDropDown(true);
                $objValidation1->setErrorTitle('Input error');
                $objValidation1->setError('Value is not in list.');
                $objValidation1->setPromptTitle('Pick from list');
                $objValidation1->setPrompt('Please pick a value from the drop-down list.');
                $objValidation1->setFormula1('"'. implode(',',$items).'"');

            }
$items=array('1,2,3','4,5,6');
对于($x=0;$xexcel->getActiveSheet()->getCell('C'.$arr_cell[$x].')->getDataValidation();
$objValidation1->setType(phpexcell\u Cell\u DataValidation::TYPE\u LIST);
$objValidation1->setErrorStyle(PHPExcel\u单元\u数据验证::样式\u信息);
$objValidation1->setAllowBlank(false);
$objValidation1->setShowInputMessage(true);
$objValidation1->setShowErrorMessage(true);
$objValidation1->setShowDropDown(true);
$objValidation1->setErrorTitle(“输入错误”);
$objValidation1->setError('值不在列表中');
$objValidation1->setpromptitle(“从列表中选择”);
$objValidation1->setPrompt('请从下拉列表中选择一个值');
$objValidation1->setFormula1(“”。内爆(“,”,$items)。”);
}
希望这将帮助您

假设“getCell('C'.$arr\u cell[$x].')”返回Cn Cn+1 Cn+2,以此类推,循环通过$arr\u行

如果不需要验证且只想显示下拉列表:=

$items=数组('1,2,3','4,5,6')

对于($x=0;$x
这回答了你的问题吗?
$items = array ('one, two, three', 'four, five, six');
    for($x = 0; $x < count($arr_row); $x++){

                $objValidation1 = $this->excel->getActiveSheet()->getCell('C'.$arr_cell[$x].'')->getDataValidation();
                $objValidation1->setType( PHPExcel_Cell_DataValidation::TYPE_LIST );
                $objValidation1->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION );
                $objValidation1->setAllowBlank(false);
                $objValidation1->setShowInputMessage(true);
                $objValidation1->setShowErrorMessage(true);
                $objValidation1->setShowDropDown(true);
                $objValidation1->setErrorTitle('Input error');
                $objValidation1->setError('Value is not in list.');
                $objValidation1->setPromptTitle('Pick from list');
                $objValidation1->setPrompt('Please pick a value from the drop-down list.');
                $objValidation1->setFormula1('"'. implode(',',$items).'"');

            }
            $objVal = $this->excel->getActiveSheet()->getCell('C'.$arr_cell[$x])->getDataValidation();
            $objVal->setType( PHPExcel_Cell_DataValidation::TYPE_LIST );
            $objVal->setShowDropDown(true);
            $objVal->setFormula1('"'. implode(',',$items).'"');

        }