So the first step in the job is to get the data out of Excel. Here I use an open source PHP processing Excel class: Phpexcel. The details of the project are http://phpexcel.codeplex.com/.
I am currently using the phpexcel1.7.3 version, there is a phpexcel and phpexcel.php file after decompression.
We mainly use that PHP file. See File directory structure
This version is said to support excel2007, but I can't get support for this library with the 2007 edition of Xlsx. So I turned it into 2003. Feeling supportive is very good.
Here are some specific uses:
Copy CodeThe code is as follows:
Require_once ('./phpexcel1.7.3/phpexcel.php ');
$php _excel_obj = new Phpexcel ();
$php _reader = newphpexcel_reader_excel2007 ();
if (! $php _reader->canread ($file _name))
{
$php _reader= new Phpexcel_reader_excel5 ();
if (! $php _reader->canread ($file _name))
{
Echo ' NO excel! ';
}
}
$php _excel_obj = $php _reader->load ($file _name);
$current _sheet = $php _excel_obj->getsheet (0);
The main function above is to initialize the relevant Excel class and load Excel first sheet
$all _column = $current _sheet->gethighestcolumn ();
$all _row = $current _sheet->gethighestrow ();
The maximum column values of the table are obtained (the letters are denoted as: ' G '), and the maximum number of rows (numeric representation)
The following will use loops to read the data in Excel in Excel:
Copy CodeThe code is as follows:
$all _arr = Array ();
$c _arr = Array ();
Character comparison table
for ($r _i = 1; $r _i<= $all _row; $r _i++)
{
$c _arr= Array ();
for ($c _i= ' A '; $c _i<= ' B '; $c _i++)
{
$adr = $c _i. $r _i;
$value = $current _sheet->getcell ($ADR)->getvalue ();
if ($c _i== ' A ' && Empty ($value))
Break
if (Is_object ($value))
$value = $value->__tostring ();
$c _arr[$c _i]= $value;
}
$c _arr&& $all _arr[] = $c _arr;
}
The following is a brief introduction to Phpexcel's write operation, which is often used to import data from a database into Excel for easy presentation and more aesthetic results.
Copy CodeThe code is as follows:
Require_once ('./phpexcel1.7.3/phpexcel.php ');
$excel _obj = new Phpexcel ();
$objWriter = Newphpexcel_writer_excel5 ($excel _obj);
$excel _obj->setactivesheetindex (0);
$act _sheet_obj= $excel _obj->getactivesheet ();
$act _sheet_obj->settitle (' sheet ');
$act _sheet_obj->setcellvalue (' A1 ', ' string content ');
$act _sheet_obj->setcellvalue (' A2 ', 26);
$file _name = "Output.xls";
$objWriter->save ($file _name);
The code is simple, first initializing the relevant Excel write class, then writing the data, and finally saving it as an XLS file.
The effect of the output is shown in figure
http://www.bkjia.com/PHPjc/322114.html www.bkjia.com true http://www.bkjia.com/PHPjc/322114.html techarticle so the first step in the job is to get the data out of Excel. Here I use an open source PHP processing Excel class: Phpexcel. The project details http://phpexcel.codeplex.com ...