gpt4 book ai didi

PHPExcel 文件格式或扩展名无效 2

转载 作者:行者123 更新时间:2023-12-04 22:02:03 24 4
gpt4 key购买 nike

我正在使用 phpexcel 将我的查询导出到 excel 文件中;但是在我创建文件(这是 xslx 格式)之后,我无法在 excel 中打开我的文件。它给出“文件格式或扩展名无效。如果我尝试使用 OpenOffice Calc 打开它会正确打开。但 excelviewer 无法打开。

    <?php
require 'Classes/PHPExcel.php';
require 'Classes/PHPExcel/Writer/Excel2007.php';
require "database.php";
require "C_TahsilatGetir.php";

$obj = new TahsilatGetir;
$bitis = $obj->getExcelLastDate();
$baslangic = date("d/m/Y");
$tahsilatlar = $obj->tahsilatGetirTarih($bitis["son_tarihi"], $baslangic);

// Create new PHPExcel object
echo date('H:i:s') . " Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();

// Set properties
echo date('H:i:s') . " Set properties\n";
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");

// Add some data
echo date('H:i:s') . " Add some data\n";
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'SIRA');
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'MÜŞTERİ NO');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'ÜNVAN');
$objPHPExcel->getActiveSheet()->SetCellValue('D1', 'BÖLGE');
$objPHPExcel->getActiveSheet()->SetCellValue('E1', 'GELEN TUTAR');
$objPHPExcel->getActiveSheet()->SetCellValue('F1', 'TARİH');
$objPHPExcel->getActiveSheet()->SetCellValue('G1', 'AÇIKLAMA');
$k = 2;
for ($i = 0; $i < count($tahsilatlar); $i++) {
if ($tahsilatlar[$i]["tahsilat_turu"] == "Kredi Kartı") {
$cell1 = "A".$k;
$cell2 = "B".$k;
$cell3 = "C".$k;
$cell4 = "D".$k;
$cell5 = "E".$k;
$cell6 = "F".$k;
$cell7 = "G".$k;
$sira = $k - 1;
$objPHPExcel->getActiveSheet()->SetCellValue($cell1, $sira);
$objPHPExcel->getActiveSheet()->SetCellValue($cell2, $tahsilatlar[$i]["musteri_no"]);
$objPHPExcel->getActiveSheet()->SetCellValue($cell3, $tahsilatlar[$i]["musteri_unvani"]);
$objPHPExcel->getActiveSheet()->SetCellValue($cell4, $tahsilatlar[$i]["bolge"]);
$objPHPExcel->getActiveSheet()->SetCellValue($cell5, $tahsilatlar[$i]["tutar"]);
$objPHPExcel->getActiveSheet()->SetCellValue($cell6, $tahsilatlar[$i]["tahsilat_tarihi"]);
$objPHPExcel->getActiveSheet()->SetCellValue($cell7, $tahsilatlar[$i]["banka"]);
$k++;
}
}

// Rename sheet
echo date('H:i:s') . " Rename sheet\n";
$objPHPExcel->getActiveSheet()->setTitle('Simple');


// Save Excel 2007 file
echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="KREDIKARTI.xlsx"');
$objWriter->save('php://output');

// Echo done
echo date('H:i:s') . " Done writing file.\r\n";
?>

最佳答案

始终确保 PHPExcel 保存流是 仅限 当您将输出直接发送到浏览器 (php://output) 时会生成输出。这意味着任何 echo 或 print 语句,如

echo date('H:i:s') . " Create new PHPExcel object\n";

或者
echo date('H:i:s') . " Done writing file.\r\n";

不得在你的脚本中使用

关于PHPExcel 文件格式或扩展名无效 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32636812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com