在书中找到无法阅读的内容
Content that could not be read was found in the book
每次制作xlsx文件,打开都报错:“在书中找到无法阅读的内容”。
代码:
function getNameFromNumber($num) {
$numeric = ($num - 1) % 26;
$letter = chr(65 + $numeric);
$num2 = intval(($num - 1) / 26);
if ($num2 > 0) {
return getNameFromNumber($num2) . $letter;
} else {
return $letter;
}
}
require_once $_SERVER['DOCUMENT_ROOT'] . '/local/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$objPHPExcel = new Spreadsheet();
$date = date("Y-m-d H:i:s");
// Set document properties
$objPHPExcel->getProperties()
->setTitle("Выгрузка заявлений от" . $date)
->setSubject("Выгрузка заявлений от" . $date)
->setDescription("Выгрузка заявлений по фильтру от" . $date);
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Выгрузка заявлений по фильтру');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
$headers = ['ID', 'Фамилия абитуриента', 'Имя абитуриента', 'Отчество абитуриента', 'EMAIL', 'Статус', 'Условния приема', 'Уровень образования', 'Дата отправки заявления'];
if($arParams['GET_DOCS'] == 'Y')
$headers[] = 'Ссылки на файлы';
$activeSheet = $objPHPExcel->setActiveSheetIndex(0);
foreach( $headers as $key => $header ){
$activeSheet->setCellValue(getNameFromNumber($key + 1) . '1' , $header);
}
foreach($arResult["ITEMS"] as $rowIndex => $arItem){
//Here i prepare $row to set values
$c = 0;
foreach($row as $columnIndex => $item ){
$c++;
$activeSheet->setCellValue(getNameFromNumber($c) . (2+$rowIndex) , $item);
}
$c = 0;
foreach($row as $columnIndex => $item ){
$c++;
$activeSheet->getColumnDimension(getNameFromNumber($c))->setAutoSize(true);
}
}
$APPLICATION->RestartBuffer();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $date . '.xlsx"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xlsx');
$writer->save('php://output');
我试图制作空文件 -
$objPHPExcel = new Spreadsheet();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="123.xlsx"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xlsx');
$writer->save('php://output');
没用。错误没有消失
我的 MS Excel 可以正确恢复此文件,但无法在 OpenOffice 或其他软件中打开,因此我的客户端无法在 MAC 上打开它。我该如何解决这个问题?
mb_internal_encoding('latin1');
这有帮助
每次制作xlsx文件,打开都报错:“在书中找到无法阅读的内容”。
代码:
function getNameFromNumber($num) {
$numeric = ($num - 1) % 26;
$letter = chr(65 + $numeric);
$num2 = intval(($num - 1) / 26);
if ($num2 > 0) {
return getNameFromNumber($num2) . $letter;
} else {
return $letter;
}
}
require_once $_SERVER['DOCUMENT_ROOT'] . '/local/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$objPHPExcel = new Spreadsheet();
$date = date("Y-m-d H:i:s");
// Set document properties
$objPHPExcel->getProperties()
->setTitle("Выгрузка заявлений от" . $date)
->setSubject("Выгрузка заявлений от" . $date)
->setDescription("Выгрузка заявлений по фильтру от" . $date);
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Выгрузка заявлений по фильтру');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
$headers = ['ID', 'Фамилия абитуриента', 'Имя абитуриента', 'Отчество абитуриента', 'EMAIL', 'Статус', 'Условния приема', 'Уровень образования', 'Дата отправки заявления'];
if($arParams['GET_DOCS'] == 'Y')
$headers[] = 'Ссылки на файлы';
$activeSheet = $objPHPExcel->setActiveSheetIndex(0);
foreach( $headers as $key => $header ){
$activeSheet->setCellValue(getNameFromNumber($key + 1) . '1' , $header);
}
foreach($arResult["ITEMS"] as $rowIndex => $arItem){
//Here i prepare $row to set values
$c = 0;
foreach($row as $columnIndex => $item ){
$c++;
$activeSheet->setCellValue(getNameFromNumber($c) . (2+$rowIndex) , $item);
}
$c = 0;
foreach($row as $columnIndex => $item ){
$c++;
$activeSheet->getColumnDimension(getNameFromNumber($c))->setAutoSize(true);
}
}
$APPLICATION->RestartBuffer();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $date . '.xlsx"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xlsx');
$writer->save('php://output');
我试图制作空文件 -
$objPHPExcel = new Spreadsheet();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="123.xlsx"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($objPHPExcel, 'Xlsx');
$writer->save('php://output');
没用。错误没有消失
我的 MS Excel 可以正确恢复此文件,但无法在 OpenOffice 或其他软件中打开,因此我的客户端无法在 MAC 上打开它。我该如何解决这个问题?
mb_internal_encoding('latin1');
这有帮助