PHPExcel reader -- help required
how do we get the sheet name ( bcoz in
one excel there are 7 sheets )?
To get the current active sheet:
$sheetName = $objPHPExcel->getActiveSheet()->getTitle();
time changed into some integer value,
that shoud be same as in excel sheet
Look at PHPExcel_Shared_Date::ExcelToPHP($excelDate) or PHPExcel_Shared_Date::ExcelToPHPObject($excelDate) to convert the date/time values to a PHP timestamp or DateTime object
Have a look at the $objPHPExcel->getActiveSheet()->toArray() method rather than looping through all the rwos and columns yourself. If you want to use toArray with the formatted argument though, don't use $objReader->setReadDataOnly(true); otherwise PHPExcel can't distinguish between a number and a date/time. The latest SVN code has added a rangeToArray() method to the worksheet object, which allows you to read a row (or block of cells) at a time, e.g. $objPHPExcel->getActiveSheet()->rangeToArray('A1:A4')
The rest of your questions are basically PHP array manipulation
EDIT
PS. Instead of just telling us that the manual is really really very bad... tell us how we can improve it.
EDIT 2
Using the latest SVN code to take advantage of the rangeToArray() method:
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$headingsArray = $objWorksheet->rangeToArray('A1:'.$highestColumn.'1',null, true, true, true);
$headingsArray = $headingsArray[1];
$r = -1;
$namedDataArray = array();
for ($row = 2; $row <= $highestRow; ++$row) {
$dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
++$r;
foreach($headingsArray as $columnKey => $columnHeading) {
$namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
}
}
}
echo '<pre>';
var_dump($namedDataArray);
echo '</pre><hr />';
unable to write data using phpexcel
Forgot to add the line
$objWriter->save($filepath);
Now the code is working fine.
PHPExcel how to use data from reader
Please read the documentation chapter 4.5 (included in the PHPExcel download package)
Get a cell type using PHPExcel
Using
$rowData = $sheet->rangeToArray(
'A' . $i . ':' . $highestColumn . $i,
NULL,
True,
False
);
will give you raw values back from the range rather than formatted values
Alternatively, for an individual cell, you can use
$sheet->getCell('A8')->getDataType();
to get the actual datatype stored in the cell. The list of datatypes is defined in Classes/PHPExcel/Cell/DataType.php
const TYPE_STRING2 = 'str';
const TYPE_STRING = 's';
const TYPE_FORMULA = 'f';
const TYPE_NUMERIC = 'n';
const TYPE_BOOL = 'b';
const TYPE_NULL = 'null';
const TYPE_INLINE = 'inlineStr'; // Rich text
const TYPE_ERROR = 'e';
PHPExcel file cannot open file because the file format or file extension is not valid
I got it working now! Thanks to this phpexcel to download
I changed the code to this:
// Save Excel 2007 file
#echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
// We'll be outputting an excel file
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="payroll.xlsx"');
$objWriter->save('php://output');
I think this line:
ob_end_clean();
solved my problem.
Related Topics
Automatic Logout After 15 Minutes of Inactive in PHP
Creating a Related or Similar Posts Using PHP & MySQL
Call ASP.NET Web Service from PHP with Multiple Parameters
How to Install Ffmpeg in Wampserver 2.0 (Windows Xp)
Get String Between - Find All Occurrences PHP
How to Make Laravel Eloquent "In" Query
How to Force Formrequest Return JSON in Laravel 5.1
How to Retrieve All Variables from a Twig Template
How to Get the Last Char of a String in PHP
How to Check If an Entered Value Is Currency
Laravel 5 on PHP Artisan Config:Clear Generated Closure::_Set_State() Error
PHP Regex to Remove Http:// from String
How to Keep the Chinese or Other Foreign Language as They Are Instead of Converting Them into Codes
How to Get a User's Instagram Feed
Check to See If an Email Is Already in the Database Using Prepared Statements