如何从Excel文件中填写下拉列表

时间:2019-02-06 11:23:33

标签: excel forms symfony dropdown

我有一个下拉列表,应该从excel文件列中填写 现在,我直接填写列表:

Formbuilder:

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
->add('Author', ChoiceType::class, array(
                'choices'  => array(
                    'Author1' => 'Author1',
                    'Author2' => 'Author2',
                    'Author3' => 'Author3'

                )))
;
    }

树枝

<div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
        {{ form_widget(form.Author, {'attr': {'class' : 'form-control '}}) }}
    </div>

在表单生成器中可以吗?

1 个答案:

答案 0 :(得分:1)

  • 您可以使用phpoffice / phpexcel来读取Excel文件(使用服务会很好):http://www.techchattr.com/how-to-read-excel-files-with-php
  • 将其作为参数添加到FormBuilder定义中,例如:

    $ data = $ options ['data'];

  • 将其作为字段的“选择”传递

  • 然后,将数据作为formbuilder的参数传递,例如($ data包含来自phpExcel的信息):

    $form = $this->createForm(YourType::class, $entity, ['data' => $data]);