Import an excel file of type .xlsx

There is a problem importing a file of type : xlsx
While it works successfully with excel type: xls

Processed 2 of 147 logs from leaders.xlsx (success: 0, failed: 2)
Maximum number of errors (1) exceededProcessed 147 of 147 logs from leaders.xls (success: 147, failed: 0)Please solve because the excel files contain both types

  1. Make sure the first row of your .xlsx file is field names. If not, you need to set headerRowNumber by Page_Importing server event.
  2. Make sure the data starts from the first column.

I use $options[“offset”] = 8; // Skip the first 9th recordsThe same code works with the type xls It does not work with the type xlsx

// Page Importing event
function Page_Importing(&$builder, &$options) {
	//var_dump($builder); // Import data reader
	//var_dump($options); // Show all options for importing
	//return FALSE; // Return FALSE to skip import
$options["headers"] = ["GENDER","Email","phone","Work_Phone","Mopaul","Directors_name","g","Identity","i","Number_students","number_classes","l","m","School_name","SchoolID","SectID","q","r","Management"];
	$options["offset"] = 8; // Skip the first 9th records

	return TRUE;
}

If the header is not the first row, you need to set “headerRowNumber”, not “offset”. The “offset” setting is the data to skip when importing, not the rows to skip when reading the spreadsheet.

arbei wrote:

If the header is not the first row, you need to set
“headerRowNumber”, not “offset”. The “offset”
setting is the > data > to skip when importing, not the rows to skip when
reading the spreadsheet.

Is it possible to convert the code to headerRowNumber ???Where do I put the code?

arbei wrote:

you need to set > headerRowNumber > by > Page_Importing > server event

Can you help me convert this code to headerRowNumber

// Page Importing event
function Page_Importing(&$builder, &$options) {
	//var_dump($builder); // Import data reader
	//var_dump($options); // Show all options for importing
	//return FALSE; // Return FALSE to skip import
$options["headers"] = ["GENDER","Email","phone","Work_Phone","Mopaul","Directors_name","g","Identity","i","Number_students","number_classes","l","m","School_name","SchoolID","SectID","q","r","Management"];
	$options["offset"] = 8; // Skip the first 9th records
	return TRUE;
}

You simply set it like you set the $options[“headers”].