Export HTML Table to Excel with TableExport (No jQuery) — Copy-Ready Code


Programming Export HTML Table to Excel with TableExport (No jQuery) — Copy-Ready Code

15 Aug 2024 18:00 918 reads

จากบทความที่แล้วที่แนะนำวิธีการ Import ข้อมูลจากไฟล์ Excel โดยใช้ library ของ phpoffice/phpspreadsheet ไปแล้วนั้น วันนี้เรามาดูวิธีการ Export ข้อมูลจากตารางที่ต้องการส่งออกเป็นไฟล์ excel กันครับ มาดูกันเลยว่ามีวิธีการทำอย่างไร

สำหรับคนที่ต้องการกลับไปดูวิธีการ import ข้อมูลจาก excel สามารถกดลิงค์นี้เพื่อเข้าไปอ่านได้เลยครับ วิธี Import ข้อมูลจาก Excel โดย PHP ใช้ phpoffice/phpspreadsheet

1. ติดตั้งไลบรารี

  • สามารถ download ไฟล์จากเว็บไซต์ tableexport ได้เลยครับ tableExport

 

2. สร้างไฟล์ PHP

 

  • สร้างไฟล์ php เพื่อทดลองส่งออกข้อมูลเป็นไฟล์ excel
  • ประกาศ tag เพื่อเรียกใช้ตัว libray tableExport เพื่อเป็นฟังก์ชันในการทำงานต่อไป
    
    
    

 

3. เขียนตารางที่ต้องการ export เป็นข้อมูลในไฟล์ excel

 

  • ในส่วนของตัว body เราจะสร้่างตารางที่ประกอบด้วยข้อมูลตัวอย่างลงไป

 
>First name/td> >Last name/td> >Sex/td> >Mobile/td>
Mr. A AAA Male 123456
Mr. B BBB Male 78910
Mr. C CCC Female 111213
Mr. D DDD Male 141516
Mr. E EEE Female 171819

 

4. การเรียกใช้งาน export excel

 

  • เขียนปุ่มสำหรับกดเรียกใช้งานฟังก์ชั่น tableexport เพื่อส่งออกข้อมูลตารางที่เราต้องการ




แล้วนำโค้ดของทุกส่วนมารวมกันครับ


First name Last name Sex Mobile
Mr. A AAA Male 123456
Mr. B BBB Male 78910
Mr. C CCC Female 111213
Mr. D DDD Male 141516
Mr. E EEE Female 171819

ผลลัพธ์ที่ได้จากหน้าจอ เมื่อกดปุ่ม export ก็จะสามารถส่งออกข้อมูลมาเป็นไฟล์ excel ได้แล้วง่ายๆ ลองนำวิธีนี้ไปใช้งานกันดูได้นะครับ และมีส่วนเสริมให้ใช้ปรับแต่งเพิ่มเติมได้ ลองไปศึกษาคู่มือในเว็บไซต์ของ tableExport กันได้เลย









Please rate your satisfaction with this article

Star 1 Star 2 Star 3 Star 4 Star 5

Post a Comment
Your email address will not be displayed to others. Required fields are marked *

CAPTCHA





Recommended Content

What Is Cursor AI? The Intelligent Code Editor That Combines AI Power with VS Code
(02/11/2025 12:45)
Cursor AI is an AI-powered code editor built on top of Visual Studio Code (VS Code). It offers a familiar, flexible int…
Read more
How to reset your iPhone when it is locked with the message
(01/02/2025 12:00)
If your iPhone shows the message "iPhone Unavailable" and you can’t unlock it, you’ll need to perform a Factory Reset a…
Read more
What is og : Open Graph, and what is its significance in SEO for Facebook and social media?
(07/08/2024 11:15)
Open Graph is a protocol developed by Facebook that is used to connect websites with social media platforms through the…
Read more
How to Add the Facebook Comments Plugin to Your Website — Full Guide + Code
(07/08/2024 11:15)
Using the Facebook Comments Plugin on your website is a great way to increase user engagement and make it easy for them…
Read more
Import Excel to PHP with phpoffice/phpspreadsheet – Step-by-Step Guide with Code
(06/08/2024 10:00)
phpoffice/phpspreadsheet is a popular PHP library used for working with Excel files, including creating new files, read…
Read more
How to Create and Submit a Sitemap to Google Search Console – Improve SEO Visibility
(05/08/2024 09:30)
What is a Google Search Console Sitemap? A Google Search Console Sitemap, or simply a sitemap, is like a map you create…
Read more
How to Send LINE Notify Alerts with MQL5 – Step-by-Step Guide
(06/07/2024 08:30)
What is MQL5? MQL5 (MetaQuotes Language 5) is a programming language developed by MetaQuotes Software Corp. for writing…
Read more
Learn MQL5 Programming – Beginner’s Guide to Automated Trading in MetaTrader 5
(20/06/2024 17:30)
MQL5 (MetaQuotes Language 5) is a programming language developed by MetaQuotes Software Corp. for writing automated tra…
Read more