I have a big excel file that looks like this:
I would like to put each row into an array.
Is this possible to access the first row's order id
like this?
$result[0][2] // returns 7432
Assuming the actual first row that gives prefix for the columns' name is not present.
How could I do that?
Copy the table below and paste it into Excel in cell A1. Be sure to select cells E2:E11, enter the formula =C2:C11*D2:D11, and then press Ctrl+Shift+Enter to make it an array formula.
Establish a ConnectionOpen the connection to Excel by calling the odbc_connect or odbc_pconnect methods. To close connections, use odbc_close or odbc_close_all. $conn = odbc_connect("CData ODBC Excel Source","user","password"); Connections opened with odbc_connect are closed when the script ends.
Loading a Spreadsheet File $inputFileName = './sampleData/example1. xls'; /** Load $inputFileName to a Spreadsheet Object **/ $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); See samples/Reader/01_Simple_file_reader_using_IOFactory. php for a working example of this code.
Create an Array in PHP In PHP, there are three types of arrays: Indexed arrays - Arrays with a numeric index. Associative arrays - Arrays with named keys. Multidimensional arrays - Arrays containing one or more arrays.
I recommended to use PHPEXCEL library
https://github.com/PHPOffice/PHPExcel
you can see an example
Update: Now the alternative to this library is phpspreadsheet
Save the spreadsheet as a CSV, then use PHP's built-in CSV functions. See the sample code here:
http://php.net/manual/en/function.fgetcsv.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With