阅读下拉列表中的选项列表 - Phpexcel

时间:2013-08-22 10:31:15

标签: phpexcel

我想阅读excel表格下拉列表中给出的选项列表。

例如: - 有一个单元格(86,G)作为选项未尝试但它是一个下拉列表。因此,无论用户选择什么,我都想从下拉列表中读取最后一个选项。

enter image description here

如何实现这一目标?

由于

2 个答案:

答案 0 :(得分:1)

    $bankAccounts = "bankAccounts, bankAccounts2";
    $products = "product1, product2";         

     \Excel::create('file', function ($excel) use ($bankAccounts, $products) {
        $excel->sheet('Sale Forecasting', function ($sheet) use ($bankAccounts, $products) {
            $sheet->SetCellValue('A1', 'name');
            $sheet->SetCellValue('A2', 'testing');
            $sheet->SetCellValue('B1', 'valid_from');
            $sheet->SetCellValue('B2', '2020-01');
            $sheet->SetCellValue('C1', 'valid_till');
            $sheet->SetCellValue('C2', '2020-02');
            $sheet->SetCellValue('D1', 'amount');
            $sheet->SetCellValue('D2', '1000');
            $sheet->SetCellValue('E1', 'bank_account');
            $sheet->SetCellValue('F1', 'product');
            $sheet->SetCellValue('G1', 'description');
            $sheet->SetCellValue('G2', 'Lorem ipsum');
            $col_count = 1000;
            for ($i = 2; $i <= $col_count; $i++) {
                $objValidation = $sheet->getCell('E'.$i)->getDataValidation();
                $objValidation->setType(\PHPExcel_Cell_DataValidation::TYPE_LIST);
                $objValidation->setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION);
                $objValidation->setAllowBlank(false);
                $objValidation->setShowInputMessage(true);
                $objValidation->setShowErrorMessage(true);
                $objValidation->setShowDropDown(true);
                $objValidation->setErrorTitle('Input error');
                $objValidation->setError('Value is not in list.');
                $objValidation->setPromptTitle('Pick from list');
                $objValidation->setPrompt('Please pick a value from the drop-down list.');
                $objValidation->setFormula1('"'.$bankAccounts.'"');
            }

            $col_count = 1000;
            for ($i = 2; $i <= $col_count; $i++) {
                $objValidation = $sheet->getCell('F'.$i)->getDataValidation();
                $objValidation->setType(\PHPExcel_Cell_DataValidation::TYPE_LIST);
                $objValidation->setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION);
                $objValidation->setAllowBlank(false);
                $objValidation->setShowInputMessage(true);
                $objValidation->setShowErrorMessage(true);
                $objValidation->setShowDropDown(true);
                $objValidation->setErrorTitle('Input error');
                $objValidation->setError('Value is not in list.');
                $objValidation->setPromptTitle('Pick from list');
                $objValidation->setPrompt('Please pick a value from the drop-down list.');
                $objValidation->setFormula1('"'.$products.'"');
            }
        });
    })->download('xlsx');

答案 1 :(得分:0)

按照以下步骤阅读PHPExcel中的下拉列表

步骤1:将下拉数据存储在单独的表格中

第2步:在单独的表单中创建下拉列表

请参阅以下代码。

var csv = require("fast-csv");
csv.fromPath(uploadedFiles[0].fd, {headers : true})
        .on("data", function(data){
               console.log(data);
        });

创建xls时应遵循这些步骤。

当您要阅读下拉列表时,请使用存储在第二张表格中的数据而非下拉列表。