Code Monkey home page Code Monkey logo

mini-sheets-php's Introduction

MiniSheets

Build Status

Extremely minimal and limited PHP library for creating the most basic Office Open XML and Microsoft Excel XLSX files.

Created as a learning excerise for creating the most basic possible XLSX file. See this blog post for the origin story.

Requirements

  • ZipArchive for creating XLSX files which are actually ZIP files (TODO: add support for any ZIP library).

Usage

Install it as a Composer dependency:

composer require kasparsd/mini-sheets-php

See examples for how to use it.

Contribute

All contributions are welcome! Please create an issue or open a pull request with the suggested changes.

Credits

Created by Kaspars Dambis.

mini-sheets-php's People

Contributors

kasparsd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mini-sheets-php's Issues

FIX: store numeric values in cells

What's the issue?

Currently, numerical values cannot be stored in columns. The reason is that numbers incorrectly end up in "shared strings" and their indexes are ending up in the cell - not the values itself.

Want a quick fix?

change this

$cells[] = sprintf(
'<c r="%s" t="%s"><v>%d</v></c>',
$this->escape_xml( $this->xlsx_cell_name( $row_no, $col_no ) ),
$this->escape_xml( $field_type ),
$this->escape_xml( $field_value_no )
);

into that

$cells[] = sprintf(
	'<c r="%s" t="%s"><v>%s</v></c>',
	$this->escape_xml( $this->xlsx_cell_name( $row_no, $col_no ) ),
	$this->escape_xml( $field_type ),
	$this->escape_xml( $field_type === 'n' ? $field_value : $field_value_no )
);

Make it even better

Put the creation of $field_value_no into an else clause.

Garbled output when two Xlsx files are build one after another.

To reproduce the issue, try to generate two xlsx files, like :

$zipper1 = new \ZipArchive;
$file1 = DIR . '/file1.xlsx';
$zipper1->open( $file1, \ZipArchive::CREATE | \ZipArchive::OVERWRITE );
$builder1 = new XlsxBuilder( $zipper1 );
$builder1->add_rows( $FirstDataArray );
$builder1->build();
$zipper1->close();

(tried here to unset $builder and $zipper, but with no success)

$zipper2 = new \ZipArchive;
$file2 = DIR . '/file2.xlsx';
$zipper2->open( $file2, \ZipArchive::CREATE | \ZipArchive::OVERWRITE );
$builder2 = new XlsxBuilder( $zipper2 );
$builder2->add_rows( $SecondDataArray );
$builder2->build();
$zipper2->close();

Both files are generated. First file is ok.. second, it's garbled.
With the same code, If the first block is commented, second file become perfect.

I cannot find the leak....

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.