首页 > 解决方案 > 如何从 excel 文件中加载数据然后在 Laravel 中提交?

问题描述

我希望我的用户将带有 excel 文件的产品上传到固定类别。为此,我必须使用 excel 文件的值插入一些输入字段值。我的上传表单 HTML 是:

<form action="">
    <input type="file" name="excel">
    <button id="">Load Excel File</button>
</form>
<form action="{{ route('product.store') }}" method="POST" enctype="multipart/form-data">
    @csrf
    <input type="hidden" value="25">
    <label for="">Price</label>
    <input type="text" placeholder="Product Price">
    <table>
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Phone</th>
            <th>Action</th>
        </tr>
        @foreach()
        <tr>
            <td>{{ Name }}</td>
            <td>{{ Email }}</td>
            <td>{{ Phone }}</td>
            <td>
                <a href="">Remove</a>
            </td>
        </tr>
        @endforeach
    </table>
    <button type="submit">Submit</button>
</form>

在这里,每个产品的 category_id 都是相同的。然后单价将由用户给出。然后选择excel文件。然后单击加载 excel 文件按钮。它将从 excel 文件中读取数据并将其显示在表格中。同时会匹配表头和excel文件头列。这里将只显示匹配头数据。然后用户可以检查数据。如果想要用户可以删除数据。然后提交按钮将在匹配的数据库列中为每个表列插入一行到数据库中。

我的问题是: 如何读取 excel 文件并在表格中显示数据并从表格中删除数据?是否可以使用 AJAX 或其他方式?

标签: phpjqueryajaxlaravel

解决方案


推荐阅读