本文整理汇总了PHP中Excel::excel2Array方法的典型用法代码示例。如果您正苦于以下问题:PHP Excel::excel2Array方法的具体用法?PHP Excel::excel2Array怎么用?PHP Excel::excel2Array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Excel
的用法示例。
在下文中一共展示了Excel::excel2Array方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testing
public function testing($file)
{
$getFiles = $this->getExcel();
$fileName = $getFiles[$file];
if ($fileName == false) {
$error = ["error_Message" => "You don't have any projects in folder!"];
return Response::json($error);
} else {
$testingExcel = Excel::excel2Array(base_path() . '/excelPlace/' . $fileName);
$months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
// The Month array, used to check if the current page is month page. Little bit hard cooded but what can you do :D
$currentMonth = "";
// Current month flag. According to its value we are parsing the data to the correct array key
$chartData = ["ContractData" => [], "calendar" => [], "projects" => $getFiles];
// Initial Array structure.
$role = "";
for ($i = 0; $i < count($testingExcel); $i++) {
for ($j = 0; $j < count($testingExcel[$i]); $j++) {
$currentMonth = $testingExcel[$i][$j][0][0];
/*
|------------------------------------------------------------------------------------
| **************** PREPARING DATA FOR THE LINE CHART !!! ****************** |
|------------------------------------------------------------------------------------
*/
if (in_array($currentMonth, $months)) {
// Checking if the Excel file page is the Month page
$chartData["calendar"][$currentMonth]["roles"] = [];
$chartData["calendar"][$currentMonth]["Days_in_month"] = [];
for ($k = 0; $k < count($testingExcel[$i]); $k++) {
if (isset($testingExcel[$i][$k + 2][0][0])) {
// Setting up the array structure
$role = $testingExcel[$i][$k + 2][0][0];
//$chartData["calendar"][$currentMonth]["roles"][$role]["Hourly_Rate"]="";
$chartData["calendar"][$currentMonth]["roles"][$role]["Log"] = [];
$chartData["calendar"][$currentMonth]["roles"][$role]["Used_HRS_This_Month"] = 0;
}
if (isset($testingExcel[$i][$k + 2][0][1]) && isset($role)) {
// Inserting the "Hourly Rate" value in array
//$chartData["calendar"][$currentMonth]["roles"][$role]["Hourly_Rate"]=$testingExcel[$i][$k+2][0][1];
// Looping trough the every line to get the log data
$count = count($testingExcel[$i][$k + 2][0]);
for ($t = 0; $t < $count; $t++) {
$index = count($chartData["calendar"][$currentMonth]["roles"][$role]["Log"]);
if (isset($testingExcel[$i][$k + 2][0][$t + 1]) && isset($role)) {
$chartData["calendar"][$currentMonth]["roles"][$role]["Log"][$index] = $testingExcel[$i][$k + 2][0][$t + 1];
$chartData["calendar"][$currentMonth]["roles"][$role]["Used_HRS_This_Month"] = $chartData["calendar"][$currentMonth]["roles"][$role]["Used_HRS_This_Month"] + $testingExcel[$i][$k + 2][0][$t + 1];
}
}
}
}
/*
|
| Counting the logs for each day and determinating how manny days in month we have.
| If the last reccord was "25.Decembar" the chart X label will be X = [1 , 25] and so on.
|
*/
$daysNr = count($chartData["calendar"][$currentMonth]["roles"][$role]["Log"]);
for ($d = 1; $d <= $daysNr; $d++) {
$dayIndex = count($chartData["calendar"][$currentMonth]["Days_in_month"]);
$chartData["calendar"][$currentMonth]["Days_in_month"][$dayIndex] = $d;
}
} else {
// If current page is not the Month page
/*
|------------------------------------------------------------------------------------
| ******************** PREPARING CONTRACT DATA!!! ******************* |
|------------------------------------------------------------------------------------
*/
if (array_filter($testingExcel[0][1][0])) {
if (array_key_exists($j + 2, $testingExcel[0]) && array_unique($testingExcel[0][$j + 2][0]) != array(null)) {
for ($x = 0; $x < count($testingExcel[0][$j + 2][0]); $x++) {
$contractDataKey = str_replace(" ", "_", $testingExcel[0][1][0][$x]);
$chartData["ContractData"][$contractDataKey] = [];
for ($l = 0; $l < count($testingExcel[0]); $l++) {
$chartDataKey = count($chartData["ContractData"][$contractDataKey]);
if (array_key_exists($l + 2, $testingExcel[0]) && array_unique($testingExcel[0][$l + 2][0]) != array(null)) {
if (!is_null($testingExcel[0][$l + 2][0][$x])) {
$chartData["ContractData"][$contractDataKey][$chartDataKey] = $testingExcel[0][$l + 2][0][$x];
}
}
}
}
}
} else {
$error = ["error_Message" => "You have mest up something in the 'Master' table. Check out the 'Conventions' for the 'Master'!"];
return Response::json($error);
}
}
}
}
$chartData["ContractData"]["PDO"] = array_combine($chartData["ContractData"]["Role"], $chartData["ContractData"]["PDO"]);
$chartData["ContractData"]["PDM"] = array_combine($chartData["ContractData"]["Role"], $chartData["ContractData"]["PDM"]);
$chartData["ContractData"]["Hourly_rate"] = array_combine($chartData["ContractData"]["Role"], $chartData["ContractData"]["Hourly_rate"]);
$chartData["ContractData"]["Daily_rate"] = array_combine($chartData["ContractData"]["Role"], $chartData["ContractData"]["Daily_rate"]);
return View::make('index', array('data' => json_encode($chartData)));
}
}