php excel 下拉菜单,使用 PHPExcel 遇到的一个问题:下拉列表的数据来源过长时,显示了别的正常的下拉列表的数据来源...
遇到的問題:
我們還是先來看手冊是怎么說的:
It is important to remember that any string participating in an Excel formula is allowed to be maximum 255 characters (not bytes).
當下拉列表的數據來源過長(more than 255 characters)時,該下拉列表會顯示不正確(我遇到的情況是:該下拉列表顯示了別的正常的下拉列表的數據來源)。
以下是我的解決辦法:
//----------------下拉列表數據來源過長的解決---------------------
//解決下拉框數據來源字串長度過大:將每個來源字串分解到一個空閑的單元格中
$str_list = "item1,item2,item3,......" ;
$str_len = strlen($str_list);
if ($str_len >= 255) {
$str_list_arr = explode(',', $str_list);
if ($str_list_arr) {
foreach ($str_list_arr as $i => $d) {
$c = "P" . ($i+1);
$activeSheet->setCellValue($c,$d);
}
}
$endcell = $c;
$activeSheet->getColumnDimension('P')->setVisible(false);
}
$objValidation2 = $activeSheet->getCell("A1")->getDataValidation();
$objValidation2->setType(PHPExcel_Cell_DataValidation::TYPE_LIST)
->setErrorStyle(PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
->setAllowBlank(true)
->setShowInputMessage(true)
->setShowErrorMessage(true)
->setShowDropDown(true)
->setErrorTitle('輸入的值有誤')
->setError('您輸入的值不在下拉框列表內.')
->setPromptTitle('下拉選擇框')
->setPrompt('請從下拉框中選擇您需要的值!');
if ($str_len < 255) {
$objValidation2->setFormula1('"' . $str_list . '"');
} else {
$objValidation2->setFormula1("sheet1!P1:{$endcell}");
}
更多問題 及 解決方案 請參考:
總結
以上是生活随笔為你收集整理的php excel 下拉菜单,使用 PHPExcel 遇到的一个问题:下拉列表的数据来源过长时,显示了别的正常的下拉列表的数据来源...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 对象转dict_如何将py
- 下一篇: exec导入 php,PHP exec运