Sanjoy Roy

[MCM, MCP, SCJP] – Senior PHP Programmer

Parse .xls (Excel) using PHP


XLSParser.php:

if ($fileType !='' && $fileType == 'application/vnd.ms-excel'){
		//parse xsl file
		 $ext = 'xls';
		 $filename 	= $user.'.'.$section.'.upload.'.date('Ymd').'.'.$ext;
		 copy($_FILES['file']['tmp_name'], $UPLOAD_CSV_PATH.$filename);
		 require_once '../includes/reader.php';

		$data = new Spreadsheet_Excel_Reader();
		 //set output encoding
		$data->setOutputEncoding('CP1251');
		//read the excel file through api
		$data->read($UPLOAD_CSV_PATH.$filename);
		//prepare to retun result
		$actual_data = $data->sheets[0]['cells'];

		$rowsLength	= array();
		for($i=1; $i<$max_nos; $j++){
				$allColumns[$j] = $actual_data[$i][$j];
			}
			$newRowData[] =  $allColumns;
		}
		$data = $newRowData;
  }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: