I am trying to import a file with the different header name in the excel file and the database
My excel file has a header with the name “Order ID”
but in mysql database the header name is "orderid"How can I import this file
NOTE: i don’t want to change the header name manually.
I have also read the topic Server Events for Page_Importing and Row_Import
I am unable to figure out the problemI try by puting the code in the Page_Importing as
$options[“headers”] = [“orderid”];
it also not working
From the help file: (see the topic Import Data)
The first row of the file should contain the field names to be imported. The field names MUST match the corresponding field names in the table.
However, in your case, Bishu wrote:
My excel file has a header with the name “Order ID”
but in mysql database the header name is "orderid"So you need to fix $row[“Order ID”] to $row[“orderid”] in Row_Import, e.g. by array_merge() or array_replace() as suggested above.You should not provide your own headers in Page_Importing if your Excel file has headers.
I try putting as$row[“orderid”] = $row[“Order ID”];
unset($row[“Order ID”]);
var_dump($row);
die();But I did not get the value for var_dump
instead on the Import Pop up I go the error as
“Invalid field name: Order ID”
Then you need to provide correct headers in Page_Importing. The field names MUST match the corresponding field names in the table. You also need to skip the header in your excel file by setting $options[“offset”] = 1.