S
S
Sergey Erin2020-02-19 18:35:40
PHP
Sergey Erin, 2020-02-19 18:35:40

How to implement xls import in admin panel?

Hello. I am importing data into the database from an excel file. The algorithm is such that after uploading the file, it will be possible to select the appropriate columns from the table, set them opposite the desired values ​​and add the product. I have already displayed the column headings and by means of drag n drop they can be placed in front of the necessary columns to be added to the database. But now how to implement this addition? Split each column into an array? using php excel

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2020-02-19
@artalexs

It’s not entirely clear what you have already done (as I understand it, on the frontend you made the correspondence “column in the excel file => column in the database table”), but the algorithm should be like this:
1) on the frontend you should store not only the human-readable name of the column, but also its code from the file (AZ) in hidden properties, e.g. data attributes, i.e. you need to pre-read the sheet from the excel file and parse the column names from there.
2) When you match the columns from the file and the columns from the tables, then send a request to the backend, in which this array of correspondences is checked for realizability, then you read the excel file cell by cell, prepare an sql expression and write it to the database. To speed up the insert, you can use batch insert.
PS. PHPExcel is deprecated and deprecated, check out PHPSpreadsheet .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question