Giter VIP home page Giter VIP logo

directexcel's Introduction

DirectExcel

Easily read and write into MS Excel spreadsheets

DirectExcel

Introduction

"DirectExcel" is an easy way to read and write spreadsheets in pure PHP.

There are dozens of libraries for reading/writing spreadsheets but they are far too complicated. DirectExcel makes things simpler by providing just 2 functions for reading and writing data.

Features

  • Tiny size
  • Single class file
  • Zero dependencies
  • Object-oriented usage
  • Easy to use (just 2 functions)
  • One function to create and download spreadsheets
  • Simply works with arrays

Installation

Just copy the class.directexcel.php and the fonts directory into your working path, where it is easily accessible by your PHP script.

Read data

<?php

require_once("class.directexcel.php");

// single function read
$data = DirectExcel::readArray("inventions.xlsx");

header("content-type: text/plain");
echo "Reading inventions.xlsx\n\n";

// show the data
print_r($data);

?>

Write data

<?php

require_once("class.directexcel.php");

// sample data is in array
$data = array(
	"Aircrafts" => array(
		array(
			"Name" => "SR-71 BlackBird",
			"Speed" => "Mach 3+",
		),
		array(
			"Name" => "F-22 Raptor",
			"Speed" => "Mach 1.82",
		),
	),
	"Aircraft Carrier" => array(
		array(
			"Name" => "USS Nimitz",
			"Classification" => "CVN-68",
		),
		array(
			"Name" => "USS Gerald R. Ford",
			"Classification" => "CVN-78",
		),
		array(
			"Name" => "USS Ronald Reagan",
			"Classification" => "CVN-76",
		),
	)
);

// single function write
DirectExcel::write($data, "firepower.xlsx");

header("content-type: text/plain");
echo "Excel file written successfully: \nfirepower.xlsx";

?>

You'll find plenty more to play with in the examples folder.

Data format

To make things simpler, this class was created to work with arrays. The array format for reading and writing is...

<?php
$data = array(
	"Worksheet1" => array(
		array(
			"Column1" => "Cell 1 information",
			"Column2" => "Cell 2 information",
			// more columns...
		),
		// more rows...
	),
	// more worksheets...
);
?>

Problems with CSV

CSVs are usually used as an easy way to read/write into excel format. But CSV has a lot of inherent issues.

  • When CSVs get exported into a spreadsheet software, their columns are shrinked.
  • Multiline cells look unreadable.
  • Phone numbers in cells get messed up. (e.g. +92-353-5338954 becomes -5338968).
  • Only one worksheet is supported per CSV file.
  • And it's not professional enough if you're using it on your site.

Note

  • Currently this class only supports the modern .xlsx format. The legacy .xls format is not supported.
  • This class was created during a 6 hour hackathon. A lot of testing is yet to be done.

Contributing

Please submit bug reports, suggestions and pull requests to the GitHub issue tracker. I would be happy if someone helps in its testing and extending its functionalities.

License

This software is licenced under the LGPL 2.1. Please read LICENSE for information on the software availability and distribution.

directexcel's People

Contributors

aliflux avatar

Watchers

 avatar

Forkers

sesehai

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.