本文整理汇总了PHP中Maatwebsite\Excel\Facades\Excel::setDelimiter方法的典型用法代码示例。如果您正苦于以下问题:PHP Excel::setDelimiter方法的具体用法?PHP Excel::setDelimiter怎么用?PHP Excel::setDelimiter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Maatwebsite\Excel\Facades\Excel
的用法示例。
在下文中一共展示了Excel::setDelimiter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
/**
* Test import.
*
* @return boolean
*/
public function import($fileWithPath, $delimiter = ',', $save = true)
{
$rows = Excel::setDelimiter($delimiter)->load($fileWithPath)->get();
$pagePos = -99;
$pageCounter = 1;
foreach ($rows as $row) {
// create a new step
if ($pagePos != $row->page) {
if ($pagePos >= 1) {
$page->items()->saveMany($items);
}
$page = new Page();
if (trim($row->model) == 'Comproso\\Framework\\Models\\Page') {
$params = [];
// input validation
/*$validator = Validator::make($row->toArray(), [
'recallable' => 'boolean',
'returnable' => 'boolean',
'template' => 'string',
'operations_template' => 'string',
'page_assets' => 'json'
]);
// validation fail
if($validator->fails())
{
\Log::error($validator->errors());
return false;
}*/
// set page call settings
$page->recallable = boolval($row->recallable);
$page->returnable = boolval($row->returnable);
if (!empty(trim($row->template))) {
$page->template = trim($row->template);
}
} elseif (!empty(trim($row->page_template))) {
$page->template = trim($row->page_template);
}
// set page assets
if (!empty(trim($row->page_assets))) {
$page->assets = json_encode(json_decode(trim($row->page_assets)));
}
// set operations template
if (!empty(trim($row->operations_template))) {
$page->operations_template = $row->operations_template == "null" ? null : trim($row->operations_template);
}
$page->repetitions = is_null($row->repetitions) ? 0 : $row->repetitions;
$page->repetition_interval = is_null($row->interval) ? null : $row->interval;
$page->time_limit = is_null($row->time_limit) ? null : $row->time_limit;
$page->position = $pageCounter;
$this->pages()->save($page);
$items = [];
$pagePos = $row->page;
$pageCounter++;
$itemCounter = 1;
if (trim($row->model) == 'Comproso\\Framework\\Models\\Page') {
continue;
}
}
// create Item
$item = new Item();
$item->position = $itemCounter;
$item->element_type = trim($row->model);
// create Element
$row->model = trim($row->model);
$element = new $row->model();
$element->implement($row);
$element->save();
$item->element_id = $element->id;
$item->template = empty(trim($row->template)) ? $element->template() : trim($row->template);
$item->name = empty(trim($row->name)) ? null : trim($row->name);
$item->proceed = !isset($row->proceed) ? false : boolval($row->proceed);
$item->cssId = empty(trim($row->cssid)) ? null : trim($row->cssid);
$item->cssClass = empty($row->cssclass) ? null : trim($row->cssclass);
$item->validation = empty(trim($row->validation)) ? 'string' : trim($row->validation);
$items[] = $item;
$itemCounter++;
}
// save last page
$page->items()->saveMany($items);
// set test assets
//$this->assets = (isset($testAssets)) ? json_encode($testAssets) : null;
// save if allowed
if ($save) {
$this->save();
}
return true;
}