ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์ProgrammingPHP Header Excel พอมี 2 table แล้วกำหนดความกว้่างของ td ไม่ได้คับ ทำไงดี
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: PHP Header Excel พอมี 2 table แล้วกำหนดความกว้่างของ td ไม่ได้คับ ทำไงดี  (อ่าน 623 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
BHunter
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 26



ดูรายละเอียด
« เมื่อ: 19 มิถุนายน 2017, 19:45:34 »

พอดีโปรเจคที่ทำ เป็นเกี่ยวกับการโชว์ตารางสอน หลายๆตาราง(วนลูป) โชว์ในหน้าexcel
ซึ่งก็เลยมีหลายTable (ตามจำนวนloop)

แต่ปัญหาคือ ตอนที่มี 1 table ก็กำหนดความกว้าง ของ<td> ได้ตามปกตินะ แต่พอ 2 table ขึ้นไป ก็กำหนดไม่ได้ซะงั้น

เลยอยากทราบว่าพี่ๆพอจะมีวิธีแก้ไหมครับ
ปล. (ผมลองใช้ทั้งattribute width กับcss width : ... px ไปละคับ)

โค๊ด:
<?php
header
("Content-Type: application/vnd.ms-excel; charset=TIS-620");
header('Content-Disposition: attachment; filename="report_schedule_teacher.xls"');#ชื่อไฟล์

?>


<html>
<head>


</head>
<body>

<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="300">Hello1</td>
<td width="400">Hello2</td>
</tr>
</thead>
<tbody>
<tr>
<td>World1</td>
<td>World2</td>
</tr>
</tbody>
</table>

<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="300">Why I cannot set width if I have multiple table</td>
<td width="400">Noooo</td>
</tr>
</thead>
<tbody>
<tr>
<td>kub</td>
<td>pom</td>
</tr>
</tbody>
</table>


</body>
</html>
« แก้ไขครั้งสุดท้าย: 19 มิถุนายน 2017, 19:46:53 โดย BHunter » บันทึกการเข้า
MaxKrub
สมุนแก๊งเสียว
*

พลังน้ำใจ: 61
ออฟไลน์ ออฟไลน์

กระทู้: 928



ดูรายละเอียด
« ตอบ #1 เมื่อ: 19 มิถุนายน 2017, 20:19:08 »

แนะนำใช้ PHPExcel เป็น  library ที่ใช้ในการ Export ไฟล์เป็น Excle อาจจะใช้งานง่ายกว่าครับลองศึกษาดูครับ
บันทึกการเข้า
boontam
ก๊วนเสียว
*

พลังน้ำใจ: 3
ออฟไลน์ ออฟไลน์

กระทู้: 222



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 20 มิถุนายน 2017, 09:06:23 »

เข้ามามุง ขอให้ได้ไวไวนะครับ
บันทึกการเข้า

nukerman
Newbie
*

พลังน้ำใจ: 4
ออฟไลน์ ออฟไลน์

กระทู้: 94



ดูรายละเอียด
« ตอบ #3 เมื่อ: 21 มิถุนายน 2017, 07:42:16 »

เขียนใส่แบบนี้เอาครับ style="width:100px;"
บันทึกการเข้า
worldwidewsc
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 22



ดูรายละเอียด
« ตอบ #4 เมื่อ: 21 มิถุนายน 2017, 09:32:30 »

หลาย table ก็ไม่น่าจะต่างกันนะครับ หากผมเข้าใจในคำถามผิดขออภัยนะครับ
ด้านล่างนี้ผมลองทำ หลาย table หลาย td ให้ดูครับ หากไม่ตรงกับความต้องการก็ขออภัยด้วย

โค๊ด:
<?php
header
("Content-Type: application/vnd.ms-excel; charset=TIS-620");
header('Content-Disposition: attachment; filename="report_schedule_teacher.xls"');#ชื่อไฟล์

?>


<html>
<head>


</head>
<body>

<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="356">Hello1</td>
<td width="401">Hello2</td>
<td width="402">Hello3</td>
</tr>
</thead>
<tbody>
<tr>
<td>World1</td>
<td>World2</td>
<td>Hello3</td>
</tr>
</tbody>
</table>

<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="356">Why I cannot set width if I have multiple table</td>
<td width="401">Noooo</td>
<td width="402">Hello3</td>
</tr>
</thead>
<tbody>
<tr>
<td>kub</td>
<td>pom</td>
<td>Hello3</td>
</tr>
</tbody>
</table>
<!---------------->
<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="356">Why I cannot set width if I have multiple table</td>
<td width="401">Noooo</td>
<td width="402">Hello3</td>
</tr>
</thead>
<tbody>
<tr>
<td>kub</td>
<td>pom</td>
<td>Hello3</td>
</tr>
</tbody>
</table>
<!-------->
<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="356">Why I cannot set width if I have multiple table</td>
<td width="401">Noooo</td>
<td width="402">Hello3</td>
</tr>
</thead>
<tbody>
<tr>
<td>kub</td>
<td>pom</td>
<td>Hello3</td>
</tr>
</tbody>
</table>


</body>
</html>
« แก้ไขครั้งสุดท้าย: 21 มิถุนายน 2017, 09:33:14 โดย worldwidewsc » บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์