Tag: 拉拉维尔

我在PHP中导入Excel表格时无法区分两个对象

我正在尝试使用PHP将Excel表导入数据库。 当我读表时,我得到不同格式的数据。当只有一张表被插入,我得到的数据在一个单一的数组,当我插入两张或更多的工作表,我在对象格式中获得多个数组在两种情况下。所以我无法区分单个数组和多个数组,不能在数据库中插入值。 $path = Input::file('file')->getRealPath(); $data = Excel::load($path, function($reader) {})->get(); 这里是$ data中的单张 [ { "id":1,"name":"Nilima" } ]格式和我得到的多个工作表 [ [ { "id":1,"name":"Nilima" } ], [ ], [ ] ] 。 但是这两个响应的types都是对象。 任何人都可以请帮我解决这个问题。我在这个问题上陷入困境。

Laravel擅长传递一个观点

我试图导出数据到Excel,我似乎无法使其工作。 我正在使用: http : //www.maatwebsite.nl/laravel-excel/docs 我尽可能地跟踪文档。 所以我有这个观点,我想在Excel中获得。 文件告诉我: 为单张纸张加载视图 $sheet->loadView('folder.view'); 所以我这样做,当然(我当然)我得到一个错误说,在视图中的variables没有被拒绝,因为我没有把variables传递到视图。 所以我再次阅读文档,它说: 将variables传递给视图 或者,您可以使用与Laravel视图相同的with()方法。 用一个基本with()例子。 所以现在我有我的控制器function: public function something(){ $something2=''; $something=''; Excel::create('Laravel Excel', function($excel) { $excel->sheet('Excel sheet', function($sheet) { $sheet->loadView('something')->with('something',$something) ->with('something2',$something2); $sheet->setOrientation('landscape'); }); })->export('xls'); } 现在我在控制器中得到一个错误: 未定义的variables$的东西 所以我不知道会发生什么事。 我保持积极,认为这将是一件容易的事情,实际上没有被宣布的东西,所以我删除了从Excel导出。 然后它给了我错误: 未定义的variables$ something2 在此之后,我知道还有其他的错误。 由于两者都不是根据excel的创build来“定义”的。 所以我尝试了一些新的东西。 在Excel创build中声明两个variables。 虽然在声明variables和创buildexcel之间有更多的代码。 所以这是行不通的。 所以代码是这样的: $something2=''; $something=''; //more code if($check==true){ Excel::create('Laravel […]

如何使用Laravel Excel在 – > download()之前重命名文件

在Laravel Excel的文档中找不到在下载之前如何为加载的文件提供一个新名称。 我试过 – > setTitle,但它不起作用。 Excel::load(public_path().'/bills/bill.template.xlsx', function($doc) { $doc->setTitle = 'test'; $sheet = $doc->setActiveSheetIndex(0); $sheet->setCellValue('G21', '{buyer}'); $sheet->setCellValue('AB24', '{sum}'); $sheet->setCellValue('B30', '{sum_propis}'); })->download('xlsx'); 当我等待“test.xlsx”时,它给了我“bill.template.xlsx”

导出Excel文件时调整列宽

我想通过使用下面的代码将数据从Mysql导出到Excel文件中: $stories = Story::all(); $header = 'Name' . "\t" . 'Email' . "\t" . 'Title' . "\t" . 'Created At' . "\t" . 'Story'; $xsl = $header . "\n"; foreach ($stories as $story) { $row = ''; $row .= '"' . str_replace('"', '""', stripslashes($story->name )) . '"' . "\t"; $row .= '"' . str_replace('"', '""', […]

laravel phpexcel更新中模糊的类别分辨率

我尝试使用php excel更新laravel,同时安装我在composer php中发现了下面的警告。 错误: Warning: Ambiguous class resolution, "SettingsController" was found in both "C:\xampp\htdocs\mti\app\controllers\SettingsController.php" and "C:\xampp\htdocs\mti\app\controllers\SettingsControllerBackup.php", the first will be used.Warning: Ambiguous class resolution, "ClassModel" was found in both "C:\xampp\htdocs\mti\app\models\ClassModel.php" and "C:\xampp\htdocs\mti\ app\models\LoginModel.php", the first will be used. SettingsController: <?php class SettingsController extends BaseController { public function ChangePasswordLayout() { return View::make('settings/changepassword/changepassword'); } public function ChangePasswordProcess() […]

类stdClass的对象不能被转换为string – laravel

我正在关注这个文档 在我的laravel 4项目中实现导出到Excel。 所以我想这样从数组中生成excel文件: //$results is taken with db query $data = array(); foreach ($results as $result) { $result->filed1 = 'some modification'; $result->filed2 = 'some modification2'; $data[] = $result; } Excel::create('Filename', function($excel) use($data) { $excel->sheet('Sheetname', function($sheet) use($data) { $sheet->fromArray($data); }); })->export('xls'); 但是这引起了exception: Object of class stdClass could not be converted to string 我究竟做错了什么 ? 更新: […]