王杰新 edited this page May 31, 2018 · 9 revisions

Let's start by creating a simple spreadsheet using PHP and the php-excel-writer extension.

Say that we have some data on monthly outgoings that we want to convert into an Excel XLSX file:

Item Cost
Rent 1000
Gas 100
Food 300
Gym 50

To do that we can start with a small program like the following:

$config = ['path' => '/home/viest'];

$excel = new \Vtiful\Kernel\Excel($config);

// fileName automatically creates a worksheet
// where you can automatically use the second argument to name the worksheet, 
// or you can choose to ignore the second argument
$filePath = $excel->fileName('tutorial01.xlsx', 'sheet1')
    ->header(['Item', 'Cost'])
    ->data([
        ['Rent', 1000],
        ['Gas',  100],
        ['Food', 300],
        ['Gym',  50],
    ])
    ->output();

If we run this program we should get a spreadsheet that looks like this:

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.