GithubHelp home page GithubHelp logo

mostafasy / htmlphpexcel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ticketpark/htmlphpexcel

0.0 0.0 0.0 84 KB

A php library based on PHPExcel to convert html tables to excel files.

License: MIT License

PHP 93.81% HTML 6.19%

htmlphpexcel's Introduction

HtmlPhpExcel

Build Status

This is a php library based on PhpSpreadsheet which simplifies converting html tables to excel files. It allows styling right within the html template with specific attributes.

Installation

Add HtmlPhpExcel to your composer.json:

composer require ticketpark/htmlphpexcel

Simple example

<?php

require_once('../vendor/autoload.php');

$html = '<table><tr><th>Column A</th><th>Column B</th></tr><tr><td>Value A</td><td>Value B</td></tr></table>';
$htmlPhpExcel = new \Ticketpark\HtmlPhpExcel\HtmlPhpExcel($html);

// Create and output the excel file to the browser
$htmlPhpExcel->process()->output();

// Alternatively create the excel and save to a file
$htmlPhpExcel->process()->save('myFile.xlsx');

// or get the \PhpOffice\PhpSpreadsheet\Spreadsheet object to do further work with it
$phpExcelObject = $htmlPhpExcel->process()->getExcelObject();

For a more complex example with styling options see example directory.

Styling

There is support for specific html attributes to allow styling of the excel output. The attributes expect the content to be json_encoded.

  • _excel-styles
    Supports everything which is possible with PhpSpreadsheet's applyFromArray() method (also see here).

Example:

<table>
    <tr>
        <td _excel-styles='{"font":{"size":16,"color":{"rgb":"FF0000"}}}'>Foo</td>
    </tr>
</table>
  • _excel-dimensions
    Supports changing dimensions of rows (when applied to a <tr> or <td>) or column (when applied to a <td>),

Example:

<table>
    <tr _excel-dimensions='{"row":{"rowHeight":50}}'>
        <td _excel-dimensions='{"column":{"width":20}}'>Foo</td>
    </tr>
</table>
  • _excel-explicit
    Supports applying an explicit cell value type.

Example:

<table>
    <tr>
        <td _excel-explicit='PhpSpreadsheet_Cell_DataType::TYPE_STRING'>0022</td>
    </tr>
</table>
  • _excel-comment
    Adds comment to cell.

Examle:

<table>
    <tr>
        <td _excel-comment='Comment content'>Cell value</td>
    </tr>
</table>

htmlphpexcel's People

Contributors

sprain avatar pskt avatar menhir2015 avatar amilkov avatar daveherman71 avatar fengyungithub 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.