问题描述
我已成功从 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 (将#修改为@)