|
|
|
สอบถามเรื่อง PHPWord ไม่สามารถวนลูปในการ export ได้ ซึ่งใน template.docx เป็นแบบฟอร์มที่กำหนดไว้แล้ว |
|
|
|
|
|
|
|
Code (PHP)
<?php
session_start();
if($_SESSION['Idcard'] != "admin@iveb")
{
echo "Please Login!";
exit();
}
include "connect.php";
$Idcard = $_SESSION["Idcard"];
$IdStudent = $_SESSION["IdStudent"];
//error_reporting (E_ALL ^ E_NOTICE);
$date = $_POST['date'];
$strSQL = "SELECT * FROM datastd, address where datastd.IdStudent Like '64%' AND datastd.status = 'confirm' AND datastd.refer ='complete' AND datastd.Idcard = address.Idcard AND dateRefer='$date' ORDER BY datastd.Dateupload";
$objQuery = mysqli_query($link,$strSQL);
$objResult = mysqli_num_rows($objQuery);
require_once 'PHPWord.php';
$i=1;
while($objResult = mysqli_fetch_array($objQuery))
{
$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate('Template.docx');
$amount = $objResult['cashBack'];
$cashBack = substr($amount,1);
$document->setValue('print_cashBack', $cashBack);
$document->setValue('print_dateRefer', $objResult['dateRefer']);
$document->setValue('print_PrefixTH', $objResult['PrefixTH']);
$document->setValue('print_FirstnameTH', $objResult['FirstnameTH']);
$document->setValue('print_LastnameTH', $objResult['LastnameTH']);
$document->setValue('print_IdStudent', $objResult['IdStudent']);
$document->setValue('print_subject', $objResult['subject']);
$document->setValue('print_TLB', $objResult['TLB']);
$document->setValue('print_college', $objResult['college']);
$document->setValue('print_NoH', $objResult['NoH']);
$document->setValue('print_Moo', $objResult['Moo']);
$document->setValue('print_Soi', $objResult['Soi']);
$document->setValue('print_Road', $objResult['Road']);
$document->setValue('print_canton', $objResult['canton']);
$document->setValue('print_District', $objResult['District']);
$document->setValue('print_province', $objResult['province']);
$document->setValue('print_postID', $objResult['postID']);
$document->setValue('print_tell', $objResult['tell']);
$document->setValue('print_email', $objResult['email']);
$document->setValue('print_accountCode', $objResult['accountCode']);
$document->setValue('print_bank', $objResult['bank']);
$document->setValue('print_major', $objResult['major']);
//$document->setValue('Value1', 'Sun');
//$document->setValue('Value2', 'Mercury');
//$document->setValue('Value3', 'Venus');
//$document->setValue('Value4', 'Earth');
//$document->setValue('Value5', 'Mars');
//$document->setValue('Value6', 'Jupiter');
//$document->setValue('Value7', 'Saturn');
//$document->setValue('Value8', 'Uranus');
//$document->setValue('Value9', 'Neptun');
//$document->setValue('Value10', 'Pluto');
//
//$document->setValue('weekday', date('l'));
//$document->setValue('time', date('H:i'));
$file = 'MemberLetters.docx' . $objResult[0];
$document->save($file);
if(!$file) {
// File doesn't exist, output error
die('file not found');
}
else {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
header("Content-Transfer-Encoding: binary");
readfile($file);
}
$i++;
unlink($file);
exit;
}
// Save File
?>
Tag : PHP, MySQL, Word (Word.Application), Windows
|
|
|
|
|
|
Date :
2021-10-19 16:19:03 |
By :
่jopppp |
View :
431 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2021-10-19 16:26:36 |
By :
siriwimon2559 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|