繁体   English   中英

使用 codeigniter 3 excel 创建日期范围报告列

[英]Create date range report column using codeigniter 3 excel

我想使用 ci 创建导出文件日期范围报告。

意见.php

<div class="form-group row">
                        <label for="attn_date" class="col-sm-4 col-form-label">From</label>
                        <div class="col-sm-8">
                            <input type="date" class="form-control" id="attn_from" name="attn_from">
                            <?= form_error('attn_from'); ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="attn_date" class="col-sm-4 col-form-label">To</label>
                        <div class="col-sm-8">
                            <input type="date" class="form-control" id="attn_to" name="attn_to">
                            <?= form_error('attn_to'); ?>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="daily_export_file" class="col-sm-4 col-form-label">Export Data</label>
                        <div class="col-sm-8">
                            <?= form_dropdown('export_file', ['report' => 'Report'], set_value('export_file'), 'class="form-control" id="export_file"'); ?>
                            <?= form_error('export_file'); ?>
                        </div>
                    </div>

controller.php

$querydata = $this->db->query("select a.*, b.* from db_attn a
                                    LEFT JOIN tbl_wrkhour b 
                                    ON b.id_wrkhour = a.wrk_hour WHERE attn_date between '". $this->input->post('attn_from')."' 
AND '". $this->input->post('attn_to')."'order by attn_date desc")->result();

$spreadsheet = new PhpOffice\PhpSpreadsheet\Spreadsheet();
                $sheet_name = $spreadsheet->getActiveSheet()->setTitle("Attendance Report");
                $sheet = $spreadsheet->getActiveSheet();
$highestRow = $sheet->getHighestRow();
$highestColumm = $sheet->getHighestColumn();
$dataattn = $querydata;
$sheet->setCellValue('A5', 'No');
$sheet->setCellValue('B5', 'Employee Name');
$sheet->setCellValue('C5', 'Date');
$sheet->setCellValue('D5', 'Detail');
$no = 1;
$rowx = 6;
foreach ($dataattn as $rowattn) {
                    $sheet->setCellValue('A' . $rowx, $no++);
                    $sheet->setCellValue('B' . $rowx, $rowattn->emp_name);
                    $sheet->setCellValue('C' . $rowx, $rowattn->date);
                    $sheet->setCellValue('D' . $rowx, $rowattn->attn_detail);

}

我已成功显示所有员工详细信息的日期范围。 如何转置每个日期的细节?

我导出的 excel 文件中的当前视图:

员工姓名 日期 细节
1个 啊啊啊 03-01-2023 展示
2个 bbbb 03-01-2023 离开
3个 cccc 03-01-2023 晚的
4个 啊啊啊 04-01-2023 展示
5个 bbbb 04-01-2023 展示
6个 cccc 04-01-2023 展示

预期变化:

员工姓名 03-01-2023 04-01-2023 下一列日期范围
1个 啊啊啊 展示 展示 下一个
2个 bbbb 离开 展示 下一个
3个 cccc 晚的 展示 下一个

任何想法? 请帮忙...

您可能可以直接从 SQL 获得

select
   no,
   emp_name,
   case 
      when exists (select user was present on time on 03-01-2023) then 'Present'
      when exists (select user was present late on 03-01-2023) then 'Late'
      else 'Absent'
  end as '03-01-2023',
....

创建一个辅助数组,用规则和列填充 foreach function,然后将此数组设置为 $dataattn。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM