Laravel Excel的垂直和水平阅读
我目前正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论