PHPExcel write from template file, and maintain drop down and validation checks

﹥>﹥吖頭↗ 提交于 2020-02-25 06:16:47

问题


I am trying to create an excel sheet using PHPExcel, modify the data in the excel sheet then download the modified data that I created into a template format i have stored on my server. I noticed that once I downloaded the sheet with data in it, that the error checking/data validation was gone, most of it was drop downs for valid options.

I noticed from a previous question asked here that PHPExcel doesn't support array formulas, are the dropdowns/data validation options in Excel considered array formula?

If not then how can I load the data into a Template Excel Sheet already stored on my server using PHPExcel and maintain the dropdown boxes that are already saved into the Excel Sheet?

edit: To clarify I already have an excel sheet that I am using as a template document, I am simply loading the excel sheet, adding data to it, and then saving it and sending it for download to the user. The formatting and column headers show up fine after I open the newly downloaded sheet, but validation checks/ and drop down boxes are missing.

Here is my code

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$sheet = $objPHPExcel->getActiveSheet();

$sheet->getCell('A1')->setValue('new value');
$sheet->getCell('B1')->setValue('y');

$url = 'templateFile.xlsx';
$outputFileType = PHPExcel_IOFactory::identify($url);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $outputFileType);
$objWriter->save("temp/templateFileWithData.xlsx");

in the above example code, cell B1 would have a warning text and a drop down box on it asking users to select 'Y' or 'N' as the only valid options

Thanks for any help.

来源:https://stackoverflow.com/questions/31835155/phpexcel-write-from-template-file-and-maintain-drop-down-and-validation-checks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!