การแปลงไฟล์ Microsoft Excel 2007 .xlsx เป็น text ด้วย php

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: การแปลงไฟล์ Microsoft Excel 2007 .xlsx เป็น text ด้วย php

Re: การแปลงไฟล์ Microsoft Excel 2007 .xlsx เป็น text ด้วย php

โดย mindphp » 22/03/2013 4:21 pm

แบ่งตามตัวแปล $num_cols
ครับ ทำ loop สร้างไฟล์ ใหม่ ตามจำนวน col แล้วค่อยๆ เขียนไฟล์ลงไปตาม loop row

Re: การแปลงไฟล์ Microsoft Excel 2007 .xlsx เป็น text ด้วย php

โดย ballnakata » 22/03/2013 3:41 pm

mindphp เขียน:a1 ถึง a1000 คือ sheet หรอครับ
เป็นเซลล์ครับ 1000 แถว :-D

Re: การแปลงไฟล์ Microsoft Excel 2007 .xlsx เป็น text ด้วย php

โดย mindphp » 21/03/2013 9:20 pm

a1 ถึง a1000 คือ sheet หรอครับ

Re: การแปลงไฟล์ Microsoft Excel 2007 .xlsx เป็น text ด้วย php

โดย ballnakata » 21/03/2013 12:32 pm

ถ้าผมมีข้อมูล a1 ถึง a1000 อยากจะแปลงเป็น txt เซลล์ละ 1 file เป็น a1.txt ถึง a1000.txt ครับ

ขอความช่วยเหลือด้วยครับ ขอบคุณครับ

Re: การแปลงไฟล์ Microsoft Excel 2007 .xlsx เป็น text ด้วย php

โดย tsukasaz » 07/07/2012 1:49 pm

ผลการรันโค้ดครับ
แนบไฟล์
xlsx2 (Small).JPG
xlsx2 (Small).JPG (83.28 KiB) Viewed 4299 times

Re: การแปลงไฟล์ Microsoft Excel 2007 .xlsx เป็น text ด้วย php

โดย tsukasaz » 07/07/2012 1:48 pm

ทดสอบโค้ดนะครับ ไฟล์ example.xlsx ใส่เนื้อหาไว้เหมือนกัน 3 sheet
แนบไฟล์
xlsx1.JPG
xlsx1.JPG (61.8 KiB) Viewed 4299 times

การแปลงไฟล์ Microsoft Excel 2007 .xlsx เป็น text ด้วย php

โดย tsukasaz » 07/07/2012 1:43 pm

การแปลงไฟล์ Microsoft Word 2007 .docx เป็นข้อความ text ด้วย php
การแปลงไฟล์ Microsoft PowerPoint .pptx เป็นข้อความ text ด้วย php

สำหรับการแปลงไฟล์ .xlsx จะค่อยข้างยุ่งยากกว่าไฟล์ 2 ประเภท ด้านบน เนื่องจากเนื้อหาถูกแบ่งไปตามคอลัมน์ แถว และชีท สำหรับตัวอย่างโค้ดจะใช้คลาส SimpleXLSX จาก http://www.phpkode.com/source/s/simple- ... .class.php ในการแปลงไฟล์นะครับ

ตัวอย่างโค้ดการใช้งาน แปลงไฟล์ .xlsx เป็น text ด้วย php

โค้ด: เลือกทั้งหมด

<?php
require_once 'simplexlsx.class.php';

$xlsx = new SimpleXLSX('example.xlsx');

for($j = 1; $j <= count($xlsx->sheets()); $j++) {
    list($num_cols, $num_rows) = $xlsx->dimension($j);
    echo 'Start sheet '.$j.'<br />';
    foreach( $xlsx->rows() as $r ) {
            for( $i=0; $i < $num_cols; $i++ ) {
                    echo ( (!empty($r[$i])) ? $r[$i] : '' ).' ';
            }
    }
    echo '<br />finish sheet '.$j.'<br /><br />';
}
?>
แนบไฟล์
simplexlsx.class.zip
(3.83 KiB) ดาวน์โหลดแล้ว 295 ครั้ง

ข้างบน