ออกรายงาน Excel แล้ว Error ผมใช้วิธี header ขอบคุณครับ
save as เลือก encoding เป็น ANSI
Date :
2012-01-19 12:04:30
By :
narubet
แก้แล้วก็ไม่ได้ครับ
Date :
2012-01-19 12:39:11
By :
babyprogrammer
ลอง save เป็นแบบ UTF-8 ครับ
Date :
2012-01-19 13:01:12
By :
webmaster
ลองแก้เป็น UTF-8 แล้วก็ไม่ได้ครับปกติเดิมก็เป็น UTF-8 อยู่แล้ว ไม่รู้ว่าเกิดจากอะไรครับ
Date :
2012-01-19 13:59:29
By :
babyprogrammer
โค้ด มีแค่นี้เหรือเปล่าครับ หรือว่ามีเยอะกว่านี้
ก่อนถึง if($_REQUEST['excel']){
มี echo อะไรออกไปก่อนหรือเปล่า
Date :
2012-01-19 14:21:15
By :
ไวยวิทย์
Code ทั้งหมดครับ
Code (PHP)
require_once("../../include/header.php");
$data_year = $odbc->query("SELECT MAX(year_budget) as max_year FROM pr_year_budget");
$year = $_REQUEST['year'] == "" ? $data_year[0]['max_year'] : $_REQUEST['year'];
$vill_id = $_REQUEST['location_id'] == 0 ? "" : $_REQUEST['location_id'];
$div_id = $_REQUEST['div_id'] == "" ? 0 : $_REQUEST['div_id'];
$html['year'][$year] = "selected='selected'";
$html['div_id'][$_REQUEST['div_id']] = "selected='selected'";
$data = $odbc->query("
SELECT
DISTINCT year_budget
FROM
pr_year_budget
ORDER
BY year_budget
");
foreach($data as $row){
$list['year_budget'] .= "
<option value='{$row[year_budget]}' ". $html['year'][$row['year_budget']] .">{$row[year_budget]}</option>";
}
if($div_id == '' || $div_id == 0){
$sql_where = " WHERE a.year_budget = '$year' ";
}else{
if(strlen($vill_id)==0){
$sql_where = "
,tbl_province d
WHERE
a.year_budget = '$year' AND
d.div_id = '$div_id' AND
LEFT(a.vill_id,2) = d.prov_id
";
}else{
$sql_where = "
WHERE
a.year_budget = '$year' AND
a.vill_id LIKE '$vill_id%'
";
}
}//if($div_id == '' || $div_id == 0)
//-----1.จำนวนประชากร
$data_people1 = $odbc->query("SELECT COUNT(healt) as num FROM pr_poor_member a ".$sql_where." AND a.healt = '1'");
$data_people2 = $odbc->query("SELECT COUNT(healt) as num FROM pr_poor_member a ".$sql_where." AND a.healt = '2'");
$data_people3 = $odbc->query("SELECT COUNT(healt) as num FROM pr_poor_member a ".$sql_where." AND a.healt = '3'");
$total_people = $data_people1[0]['num'] + $data_people2[0]['num'] + $data_people3[0]['num'];
$data_dis = $odbc->query("SELECT * FROM pr_disability ORDER BY dis_id ASC");
foreach($data_dis as $item_dis){
$count_dis ++;
$dis_num = $odbc->query("SELECT COUNT(dis_id) as num FROM pr_poor_member a ".$sql_where." AND a.dis_id = '".$item_dis['dis_id']."'");
$list_dis .= "
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l60'>1.3.$count_dis. ".$item_dis['dis_name']."</span></td>
<td class='cell align_c'>".( $dis_num[0]['num'] == 0 ? '-' : number_format($dis_num[0]['num']) )."</td>
<td class='cell align_c'>คน</td>
</tr>
";
}
//-----2.รายได้ 3.รายจ่าย
$data_rate = $odbc->query("SELECT * FROM pr_rate ORDER BY rate_id ASC");
foreach($data_rate as $item_rev){
$count_rev ++;
$data_rev = $odbc->query("SELECT COUNT(rev_id) as num FROM pr_poor_poverty a ".$sql_where." AND a.rev_id = ".$item_rev['rate_id']."");
$list_revenue .= "
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>2.$count_rev. ".$item_rev['rate_name']."</span></td>
<td class='cell align_c'>".( $data_rev[0]['num'] == 0 ? '-' : number_format($data_rev[0]['num']) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
";
}
foreach($data_rate as $item_pay){
$count_pay ++;
$data_pay = $odbc->query("SELECT COUNT(pay_id) as num FROM pr_poor_poverty a ".$sql_where." AND a.rev_id = ".$item_pay['rate_id']."");
$list_pay .= "
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>2.$count_rev. ".$item_pay['rate_name']."</span></td>
<td class='cell align_c'>".( $data_pay[0]['num'] == 0 ? '-' : number_format($data_pay[0]['num']) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
";
}
//-----4.การใช้สารเคมี
$data_add_pro = $odbc->query("SELECT COUNT(add_product) AS num FROM pr_poor_poverty a ".$sql_where." AND a.camical_type = '1' AND a.add_product = '1'");
$data_pest = $odbc->query("SELECT COUNT(pest) AS num FROM pr_poor_poverty a ".$sql_where." AND a.camical_type = '1' AND a.pest = '1'");
$data_use_other = $odbc->query("SELECT COUNT(use_other) AS num FROM pr_poor_poverty a ".$sql_where." AND a.camical_type = '1' AND a.use_other = '1'");
//-----5.เป็นหนี้นอกระบบ
$data_debt_total = $odbc->query("SELECT COUNT(debt_type) as num FROM pr_poor_poverty a ".$sql_where." AND a.debt_type = 1");
$data_debt = $odbc->query("SELECT * FROM pr_debt ORDER BY debt_id ASC");
foreach($data_debt as $item_debt){
$count_debt ++;
$debt_num = $odbc->query("SELECT COUNT(debt_type) as num FROM pr_poor_poverty a ".$sql_where." AND a.debt_type = 1 AND a.debt_id = ".$item_debt['debt_id']."");
$list_debt .= "
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>5.$count_debt. ".$item_debt['debt_name']."</span></td>
<td class='cell align_c'>".( $debt_num[0]['num'] == 0 ? '-' : number_format($debt_num[0]['num']) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
";
}
//-----6.อบายมุข
$data_ruin = $odbc->query("SELECT * FROM pr_ruin ORDER BY ruin_id ASC");
foreach($data_ruin as $item_ruin){
$count_ruin ++;
$ruin_num = $odbc->query("SELECT COUNT(ruin_id) as num FROM pr_poor_poverty a ".$sql_where." AND a.ruin_id = ".$item_ruin['ruin_id']."");
$total_ruin += $ruin_num[0]['num'];
$list_ruin .= "
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>6.$count_ruin. ".$item_ruin['ruin_name']."</span></td>
<td class='cell align_c'>".( $ruin_num[0]['num'] == 0 ? '-' : number_format($ruin_num[0]['num']) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
";
}
//-----7.หน่วยงานช่วยเหลือ
$data_support = $odbc->query("SELECT * FROM pr_support ORDER BY support_id ASC");
foreach($data_support as $item_sup){
$count_sup ++;
$sup_num = $odbc->query("SELECT COUNT(support_id) as num FROM pr_poor_poverty a ".$sql_where." AND a.support_id = ".$item_sup['support_id']."");
$total_sup += $sup_num[0]['num'];
$list_sup .= "
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>7.$count_sup. ".$item_sup['support_name']."</span></td>
<td class='cell align_c'>".( $sup_num[0]['num'] == 0 ? '-' : number_format($sup_num[0]['num']) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
";
}
//-----8.พ้นความยากจน
$data_wish = $odbc->query("SELECT * FROM pr_wish ORDER BY wish_id ASC");
foreach($data_wish as $item_wish){
$count_wish ++;
$wish_num = $odbc->query("SELECT COUNT(wish_id) as num FROM pr_poor_poverty a ".$sql_where." AND a.wish_id = ".$item_wish['wish_id']."");
$total_wish1 += $wish_num[0]['num'];
$list_wish .= "
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>8.$count_wish. ".$item_wish['wish_name']."</span></td>
<td class='cell align_c'>".( $wish_num[0]['num'] == 0 ? '-' : number_format($wish_num[0]['num']) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
";
}
//-----9.สถานสงเคราะห์
$data_wish1 = $odbc->query("SELECT COUNT(wish_add) as num FROM pr_poor_poverty a ".$sql_where." AND a.wish_add = 0");
$data_wish2 = $odbc->query("SELECT COUNT(wish_add) as num FROM pr_poor_poverty a ".$sql_where." AND a.wish_add = 1");
$total_wish2 = $data_wish1[0]['num'] + $data_wish2[0]['num'];
$rpt = "
<tr class='col_pink'>
<th class='cell align_c'>ข้อมูล / ประเด็น </th>
<th class='cell align_c'>จำนวน</th>
<th class='cell align_c'>หน่วยนับ</th>
</tr>
<tr class='row-1 col_blue txt_bold'>
<td class='cell'><span class='margin_l10'>1. จำนวนประชากรทั้งหมด</span></td>
<td class='cell align_c'>".( $total_people == 0 ? '-' : number_format($total_people) )."</td>
<td class='cell align_c'>คน</td>
</tr>
<tr class='row-1 col_yellow1'>
<td class='cell'><span class='margin_l30'>1.1. แข็งแรงสมบูรณ์ </span></td>
<td class='cell align_c'>".( $data_people1[0]['num'] == 0 ? '-' : number_format($data_people1[0]['num']) )."</td>
<td class='cell align_c'>คน</td>
</tr>
<tr class='row-1 col_yellow1'>
<td class='cell'><span class='margin_l30'>1.2. ชรา </span></td>
<td class='cell align_c'>".( $data_people2[0]['num'] == 0 ? '-' : number_format($data_people2[0]['num']) )."</td>
<td class='cell align_c'>คน</td>
</tr>
<tr class='row-1 col_yellow1'>
<td class='cell'><span class='margin_l30'>1.3. พิการ </span></td>
<td class='cell align_c'>".( $data_people3[0]['num'] == 0 ? '-' : number_format($data_people3[0]['num']) )."</td>
<td class='cell align_c'>คน</td>
</tr>
<tr>
$list_dis
</tr>
<tr class='row-1 col_blue txt_bold'>
<td colspan='3' class='cell'><span class='margin_l10'>2. รายได้ </span></td>
</tr>
$list_revenue
<tr class='row-1 col_blue txt_bold'>
<td colspan='3' class='cell'><span class='margin_l10'>3. รายจ่าย </span></td>
</tr>
$list_pay
<tr class='row-1 col_blue txt_bold'>
<td colspan='3' class='cell'><span class='margin_l10'>4. การใช้สารเคมี </span></td>
</tr>
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>4.1. เร่งและเพิ่มผลผลิต </span></td>
<td class='cell align_c'>".( $data_add_pro[0]['num'] == 0 ? '-' : number_format($data_add_pro[0]['num']) )."</td>
<td class='cell align_c'><!--ครัวเรือน--></td>
</tr>
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>4.2. กำจัดศัตรูพืช </span></td>
<td class='cell align_c'>".( $data_pest[0]['num'] == 0 ? '-' : number_format($data_pest[0]['num']) )."</td>
<td class='cell align_c'><!--ครัวเรือน--></td>
</tr>
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>4.3. อื่นๆ </span></td>
<td class='cell align_c'>".( $data_use_other[0]['num'] == 0 ? '-' : number_format($data_use_other[0]['num']) )."</td>
<td class='cell align_c'><!--ครัวเรือน--></td>
</tr>
<tr class='row-1 col_blue txt_bold'>
<td class='cell'><span class='margin_l10'>5. เป็นหนี้นอกระบบ</span></td>
<td class='cell align_c'>".( $data_debt_total[0]['num'] == 0 ? '-' : number_format($data_debt_total[0]['num']) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
$list_debt
<tr class='row-1 col_blue txt_bold'>
<td class='cell'><span class='margin_l10'>6. อบายมุข </span></td>
<td class='cell align_c'>".( $total_ruin == 0 ? '-' : number_format($total_ruin) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
$list_ruin
<tr class='row-1 col_blue txt_bold'>
<td class='cell'><span class='margin_l10'>7. หน่วยงานที่ได้รับความช่วยเหลืออันดับแรก </span></td>
<td class='cell align_c'>".( $total_sup == 0 ? '-' : number_format($total_sup) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
$list_sup
<tr class='row-1 col_blue txt_bold'>
<td class='cell'><span class='margin_l10'>8. ครัวเรือนที่ต้องการพัฒนาตนเองเพื่อให้พ้นความยากจน </span></td>
<td class='cell align_c'>".( $total_wish1 == 0 ? '-' : number_format($total_wish1) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
$list_wish
<tr class='row-1 col_blue txt_bold'>
<td class='cell'><span class='margin_l10'>9. ความประสงค์ให้คนในครัวเรือนได้รับการสงเคระาห์ โดยการนำไปสงเคราะห์ในสถานสงเคาระห์ </span></td>
<td class='cell align_c'>".( $total_wish2 == 0 ? '-' : number_format($total_wish2) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>9.1. ต้องการ </span></td>
<td class='cell align_c'>".( $data_wish1[0]['num'] == 0 ? '-' : number_format($data_wish1[0]['num']) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
<tr class='row-1 col_yellow2'>
<td class='cell'><span class='margin_l30'>9.2. ไม่ต้องการ </span></td>
<td class='cell align_c'>".( $data_wish2[0]['num'] == 0 ? '-' : number_format($data_wish2[0]['num']) )."</td>
<td class='cell align_c'>ครัวเรือน</td>
</tr>
";
/* Export to Excel */
if($_REQUEST['excel']){
$excelpage = "
<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">
<head>
<meta http-equiv=\"Content-type\" content=\"text/html;charset=utf-8\"/>
</head>
<body>
<table x:str BORDER=\"1\">
{$rpt}
</table>
</body>
</html>
";
header("Content-Type: application/vnd.ms-excel");
header('Content-Disposition: attachment; filename="poor_rpt1.xls"');
echo $excelpage;
exit;
}
Date :
2012-01-19 14:39:38
By :
babyprogrammer
<meta http-equiv=\"Content-type\" content=\"text/html;charset=windows-874\"/> ด้วยครับ
ประวัติการแก้ไข 2012-01-19 14:57:58
Date :
2012-01-19 14:55:59
By :
narubet
ก็ยังไม่ได้ครับ
<meta http-equiv=\"Content-type\" content=\"text/html;charset=utf-8\"/>
<meta http-equiv=\"Content-type\" content=\"text/html;charset=windows-874\"/>
จากรูปจะเป็น error หลังจากคลิกปุ่มปริ้น
Date :
2012-01-19 15:18:18
By :
babyprogrammer
Load balance : Server 03