2016-06-22 04:38
浏览 253


I want to make export data into excel in my project, i have made it, but after I check the results, the results doesnt like what I want. here I would like to make a result there is a title table.

This code my controller:

public function getExport(){
        Excel::create('Export data', function($excel) {

        $excel->sheet('Sheet 1', function($sheet) {

            ->select("log_patrols.*"," as nama_companies"," as nama_security")
                foreach($products as $product) {
                 $data[] = array(

this my problem result : result

and it should be :


my problem is how to change the number into text what i want in the header table.

what improvements do i have to make to the code to achieve my goal?

NB : i use maatwebsite/excel

图片转代码服务由CSDN问答提供 功能建议

我想在我的项目中将导出数据导入excel,我已经做到了,但在检查结果后, 结果不喜欢我想要的。 在这里我想得到一个结果有一个标题表。


 <  code> public function getExport(){
 Excel :: create('Export data',function($ excel){
 $ excel-&gt; sheet('Sheet 1',function($ sheet){
 $ products = DB :: table('log_patrols')
  - &gt; join(“cms_companies”,“”,“=”,“log_patrols.id_cms_companies”)
  - &gt;加入(“证券”  “,”“,”=“,”log_patrols.id_securities“)
  - &gt;选择(”log_patrols。*“,” as nama_companies“,” as nama_security“)
  -  &gt; get(); 
 foreach($ products as $ product){
 $ data [] = array(
 $ product-&gt; date_start,
 $ product-&gt; date_end,
 $ product-&gt  ; condition_status,
 $ product-&gt; nama_security,
 $ product-&gt; nama_companies,
  $ sheet-&gt; fromArray($ data); 
}) - &gt; export('xls'); 




我有哪些改进 必须使代码实现我的目标?

NB :我使用maatwebsite / excel

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dounabi6295 2016-06-22 05:23

    From the official docs:

    By default the export will use the keys of your array (or model attribute names) as first row (header column). To change this behaviour you can edit the default config setting (excel::export.generate_heading_by_indices) or pass false as 5th parameter:


    $sheet->fromArray($data); to $sheet->fromArray($data, null, 'A1', false, false);

    how to change the number into text what i want in the header table.

    Then you can define your own heading and prepend it to the first row of the sheet.

    $headings = array('date start', 'date end', 'status condition', 'security', 'company');
    $sheet->prependRow(1, $headings);

    That should make it work.

    解决 无用
    打赏 举报

相关推荐 更多相似问题