首先,我对PHP完全陌生,但是必须使用它将一些数据从数据库写入Excel模板。我刚刚更改了一些php文件,并根据需要对其进行了调整。
尝试打开文件时遇到的错误是:
我们发现Excel中的某些内容存在问题。
单击“修复”后,所有数据都已存在。但是我需要打开excel文件,而不会发出此通知。
Excel已完成文件级别的验证和修复。该工作簿的某些部分可能已被修复或丢弃。
这是我使用的完整代码。
//require_once('excel\Worksheet.php');
//require_once('excel\Workbook.php');
require_once('connection.php.inc');
require_once 'Classes/PHPExcel/IOFactory.php';
require_once 'Classes/PHPExcel.php';
function HeaderingExcel($filename) {
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename" );
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
}
$pdatum1 = date('d',strtotime($_POST['datum1'])).".".date('m',strtotime($_POST['datum1'])).".".date('Y',strtotime($_POST['datum1']));
$pdatum2 = date('d',strtotime($_POST['datum2'])).".".date('m',strtotime($_POST['datum2'])).".".date('Y',strtotime($_POST['datum2']));
$query = "
SELECT a.*, p.naziv, r.partija FROM posracdev a, racun r, partnera p
WHERE datum BETWEEN '".$_POST['datum1']."' AND '".$_POST['datum2']."'
AND doroc <= datum + 20
AND a.rac_broj = r.rac_broj
AND p.partija = r.partija
AND sintetik LIKE '25%'
INTO TEMP svi_novooroceni with no log";
odbc_exec($conn,$query);
$query1 = "
SELECT a.*, p.naziv, r.partija FROM posracdev a, racun r, partnera p
WHERE doroc BETWEEN '".$_POST['datum1']."' AND '".$_POST['datum2']."'
AND datum <= doroc - 20
AND a.rac_broj = r.rac_broj
AND p.partija = r.partija
AND sintetik LIKE '25%'
INTO TEMP svi_aneksirani with no log";
odbc_exec($conn,$query1);
/*------------------------------Novooroceni fizicka--------------------------------*/
$query2 = "
SELECT m.naziv naziv_poslovnice, a.naziv ime_klijenta, a.partija maticni_broj, a.rac_broj,
a.datum datum_otvaranja, a.datvaljanosti datum_dospijeca, v.naziv valuta, nvl(a.stanje_valuta,0) stanje_valuta, nvl(a.stanje_valuta*t.srednji,0) stanje_eur, a.kstopa,
ROUND (((a.datvaljanosti-a.doroc)/30),0) rok_mjeseci
FROM (
SELECT a.deviza, a.datum, a.doroc, a.rac_broj, a.naziv, a.poslovnica, a.partija, a.kstopa, a.datvaljanosti, sum(p.potrazuje-p.duguje) stanje_valuta
FROM
(SELECT * FROM svi_novooroceni
WHERE sintetik[1,4] in ('2531', '2532', '2533', '2534')) a LEFT JOIN posdnevnik p
ON a.rac_broj = p.rac_broj
AND p.sintetik LIKE '25%'
AND p.datum <= '".$_POST['datum2']."'
GROUP BY 1,2,3,4,5,6,7,8,9) a, tecaja t, matposlovnica m, valutanova v
WHERE a.deviza = t.sifra
AND t.datum = '".$_POST['datum2']."'
AND a.poslovnica = m.poslovnica
AND a.deviza = v.sifra";
$odbc_result1 = odbc_exec($conn,$query2);
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array( 'memoryCacheSize' => '128MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);
$excel = PHPExcel_IOFactory::createReader('Excel2007');
$excel = $excel->load('./Oroceni_template_OD.xlsx'); // Empty Sheet
$excel->setActiveSheetIndex(0);
$excel->getActiveSheet()->setTitle('Novooroceni_fizicka');
/*------------------------------Novooroceni fizicka------------------------------*/
$i=5;
while (odbc_fetch_row($odbc_result1))
{
$excel->getActiveSheet(1)->getCellByColumnAndRow(0, $i)->setValueExplicit(iconv('ISO-8859-2', 'utf-8//TRANSLIT',odbc_result($odbc_result1,1)), PHPExcel_Cell_DataType::TYPE_STRING);
$excel->getActiveSheet(1)->getCellByColumnAndRow(1, $i)->setValueExplicit(iconv('ISO-8859-2', 'utf-8//TRANSLIT',odbc_result($odbc_result1,2)), PHPExcel_Cell_DataType::TYPE_STRING);
$excel->getActiveSheet(1)->getCellByColumnAndRow(2, $i)->setValueExplicit(iconv('ISO-8859-2', 'utf-8//TRANSLIT',odbc_result($odbc_result1,3)), PHPExcel_Cell_DataType::TYPE_STRING);
$excel->getActiveSheet(1)->getCellByColumnAndRow(3, $i)->setValueExplicit(iconv('ISO-8859-2', 'utf-8//TRANSLIT',odbc_result($odbc_result1,4)), PHPExcel_Cell_DataType::TYPE_STRING);
$excel->getActiveSheet(1)->getCellByColumnAndRow(4, $i)->setValue(odbc_result($odbc_result1,5));
$excel->getActiveSheet(1)->getCellByColumnAndRow(5, $i)->setValue(odbc_result($odbc_result1,6));
$excel->getActiveSheet(1)->getCellByColumnAndRow(6, $i)->setValue(odbc_result($odbc_result1,7));
$excel->getActiveSheet(1)->getCellByColumnAndRow(7, $i)->setValue(odbc_result($odbc_result1,8));
$excel->getActiveSheet(1)->getCellByColumnAndRow(8, $i)->setValue(odbc_result($odbc_result1,9));
$excel->getActiveSheet(1)->getCellByColumnAndRow(9, $i)->setValue(odbc_result($odbc_result1,10));
$excel->getActiveSheet(1)->getCellByColumnAndRow(10, $i)->setValue(odbc_result($odbc_result1,11));
$i++;
}
$excel->setActiveSheetIndex(0);
$excel->getActiveSheet()-> setCellValue('D1',$pdatum1);
$excel->getActiveSheet()-> setCellValue('F1',$pdatum2);
$filename = date('d-m-Y',time()).'_Oroceni_depoziti.xlsx';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$objWriter->save('php://output');
$excel->disconnectWorksheets();
unset($excel);
odbc_free_result($odbc_result1);
odbc_close($conn);
?>
Please let me know if some other information is needed.
Thank you!