如何解决PhpSpreadsheet 清除现有单元格或范围内容
我已成功从 MysqL 表中以所需格式提取数据。但是在使用MysqL数据之前,我想清除上传格式excel表中的现有内容。我试过搜索/阅读很多文章/官方文档,但没有找到合适的。
请求帮助。
<?PHP
require ROOT.'vendor/autoload.PHP';
//specify upload file name
$inputFileName = ROOT.'upload_format.xlsx';
// Set sheetname
$sheetname = 'Instructions';
// Load $inputFileName to a Spreadsheet object
$spreadsheet = \PHPOffice\PHPSpreadsheet\IOFactory::load($inputFileName);
//Set Active sheet by sheet Name under $sheet object
$sheet = $spreadsheet->getSheetByName($sheetname);
$q1="select
id,status as value
from
xyz
where
id = '51'";
$q1r = $dbc->get_results($q1);
//merge header row
$sheet->mergeCells('D15:E15');
// Set data table header
$sheet->getCellByColumnAndRow(4,15)->setValue('Your Status');
// create heading
$sheet->getCellByColumnAndRow(4,16)->setValue('Description');
$sheet->getCellByColumnAndRow(5,16)->setValue('Mention');
// loop through actual data
if(count($q1r)>0){
$i = 17;
foreach($q1r as $row) {
$sheet->getCellByColumnAndRow(4,$i)->setValue($row['value']);
$sheet->getCellByColumnAndRow(5,$i)->setValue($row['id']);
$i = $i + 1;
}
}else{
//merge cell to display error message
$sheet->mergeCells('D17:E17');
//set error message
$sheet->getCellByColumnAndRow(4,17)->setValue('No records available');
}
//write it again to Filesystem with the same name
$writer = \PHPOffice\PHPSpreadsheet\IOFactory::createWriter($spreadsheet,"Xlsx");
$writer->save($inputFileName);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。