我想使用ci创建导出文件日期范围报告。
views.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个|aaaa|二○二三年一月三日|出席|
| 第二章|BBBB|二○二三年一月三日|离开|
| 三个|cccc的|二○二三年一月三日|迟到|
| 四个|aaaa|二○二三年一月四日|出席|
| 五个|BBBB|二○二三年一月四日|出席|
| 六个|cccc的|二○二三年一月四日|出席|
预期变化:
| 没有|员工姓名|二○二三年一月三日|二○二三年一月四日|下一栏日期范围|
| - ------|- ------|- ------|- ------|- ------|
| 1个|aaaa|出席|出席|下一个|
| 第二章|BBBB|离开|出席|下一个|
| 三个|cccc的|迟到|出席|下一个|
你知道吗?请帮帮我...
2条答案
按热度按时间azpvetkf1#
您可能可以直接从SQL获得这些信息
nfg76nw02#
创建一个helper数组,用规则和列填充到foreach函数中,然后将这个数组设置为$dataattn。