我想在导出excel模板功能上添加下拉列表。
我试图添加这些代码行,但它显示错误
严重性:警告
消息:遇到的非数值
文件名:Excel5/Worksheet.php
$items = array ('one, two, three', 'four, five, six');
$objValidation = $objPHPExcel->getActiveSheet()->getCell("C$curr_row")->getDataValidation();
$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST );
$objValidation->setFormula1('"'.implode('","', $items).'"');
这是我的控制器功能
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表格中输入下拉菜单
$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).'"');
}
希望这能帮助你
假设"getCell('C'.$arr_cell[$x].''("正在返回Cn-Cn+1 Cn+2,依此类推,循环通过$arr_row
如果不需要验证并且只想显示下拉列表:=
$items=数组("一,二,三","四,五,六"(;
对于($x=0;$x<count($arr_row($x++({
$objVal = $this->excel->getActiveSheet()->getCell('C'.$arr_cell[$x])->getDataValidation();
$objVal->setType( PHPExcel_Cell_DataValidation::TYPE_LIST );
$objVal->setShowDropDown(true);
$objVal->setFormula1('"'. implode(',',$items).'"');
}