Laravel Excel的垂直和水平阅读

发布于 2025-01-31 15:33:51 字数 1443 浏览 5 评论 0原文

我目前正在使用Laravel Excel(Maatwebsite)软件包进行Excel安装和阅读。在我的情况下,我首先需要水平读取到数据库,然后通过垂直阅读将答案添加到数据库中。

到目前为止,我已经通过标准的水平阅读过程来到问题字段,但是在 Questionanswer 列中,我需要向下阅读问题的答案。

我该怎么做? https://i.sstatic.net/ylyl1k9.png

这是我的保存过程,但我是我的保存过程不知道如何获得问答列。

public function collection(Collection $rows)
    {
        foreach ($rows as $row) {
            $IDnumber = $row['IDnumber'];
            $name = $row['firstname'];
            $exam = $row['exam'];
            $course = $row['course'];
            $courseCode = $row['coursecode'];
            $question = $row['question'];

            $user = User::withTrashed()->firstOrCreate(
                ['IDnumber' => $IDnumber],
                [
                    'IDnumber' => $IDnumber,
                    'first_name' => $firstname, 
                ]
            );

            $q_insert = \Modules\Qulak\Entities\Question::create(
                [
                    'question' => $question,
                    'question_type' => 'MCQ',
                    'user_id' => $user->id,
                    'created_by' => Auth::user()->id,
                    'updated_by' => Auth::user()->id,
                ]
            );
        }

谢谢

I am currently using Laravel Excel (Maatwebsite) package for excel installation and reading. In my scenario, I first need to read horizontally to the database and then add the answers to the same question to the database by vertical reading.

So far, I have come to the Question field with the standard horizontal reading process, but in the QuestionAnswer column I need to read the answers of the question downwards.

How can I do that?
https://i.sstatic.net/yl1k9.png

Here is my save process but I don't know how to get Question Answer column.

public function collection(Collection $rows)
    {
        foreach ($rows as $row) {
            $IDnumber = $row['IDnumber'];
            $name = $row['firstname'];
            $exam = $row['exam'];
            $course = $row['course'];
            $courseCode = $row['coursecode'];
            $question = $row['question'];

            $user = User::withTrashed()->firstOrCreate(
                ['IDnumber' => $IDnumber],
                [
                    'IDnumber' => $IDnumber,
                    'first_name' => $firstname, 
                ]
            );

            $q_insert = \Modules\Qulak\Entities\Question::create(
                [
                    'question' => $question,
                    'question_type' => 'MCQ',
                    'user_id' => $user->id,
                    'created_by' => Auth::user()->id,
                    'updated_by' => Auth::user()->id,
                ]
            );
        }

Thank You

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文