Giter Site home page Giter Site logo

ci_excel's Introduction

นำไลบราลี PHPExcel มาใช้งานร่วมกับ CodeIgniter

ดาวน์โหลดไฟล์ PHPExcel จาก gitHub แล้วแตกไฟล์ zip ดังกล่าว ก๊อปปี้เฉพาะไฟล์ที่อยู่ในแฟ้ม Classes ไปไว้ที่แฟ้ม application/third_party ดังรูป

จากนั้นให้สร้างไฟล์ php เพื่อครอบไลบราลีตัวนี้ไว้โดยบันทึกไว้ในแฟ้ม application/library เพื่อใช้เป็นตัวกลางในการเรียกใช้งาน PHPExcel ในที่นี้ ผมจะสร้างไฟล์ชื่อ Excel.php แล้วพิมพ์โค๊ดดังต่อไปนี้ลงไป ```sh

จากนั้นบันทึกไว้ที่ใดที่หนึ่งภายใต้ site ในที่นี้ผมเก็บไว้ที่ /upload ตั้งชื่อว่า student_grade.xls ขั้นตอนต่อไปสร้างไฟล์ controller เพื่อมาทดสอบ ในที่นี้ผมสร้าง controller ชื่อ test.php วางไว้ที่ /controller โดยมีรายละเอียดของโค๊ดดังนี้
public function readExcel()
{
    $this->load->library( 'excel' );
    $objReader = PHPExcel_IOFactory::load( 'uploads/student_grade.xls' );
    $sheetData = $objReader->getActiveSheet()->toArray( true, true, true, true );
    echo "<table border=1>";
    foreach ( $sheetData as $data ) {
        echo "<tr>";
        $this->writeColumn( $data['A'] );
        $this->writeColumn( $data['B'] );
        $this->writeColumn( $data['C'] );
        $this->writeColumn( $data['D'] );
        echo "</tr>";
    }
    echo "</table>";
}

public function writeColumn( $data )
{
    echo "<td>$data</td>";
}

แหล่งอ้างอิง

ci_excel's People

Contributors

taveevut avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.