PHPSpreadsheet: Putting/Showing multiple spaces (whitespace/indentation) in a cell

751 Views Asked by At

I'm using \PhpOffice\PhpSpreadsheet\Reader\Html() to read an HTML table to save into an XLSX spreadsheet. I need indentation on some rows, for example it should appear like this:

Cost of Sales
  Stock
  Courier Fees

In the HTML table it's easy using &nbsp;&nbsp;&nbsp;, but this doesn't take those multiple spaces into the Excel cells. I've tried "   " (multiple spaces) and <td style='padding-left:10px;'> and even <td style='margin-left:10px;'> just in case, all to no avail. I can't find anything on Google to assist and would appreciate any advice.

Just in case, I'll include how I'm reading/writing the HTML table stored in $incomeStatement:

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Html();
$spreadsheet = $reader->loadFromString($incomeStatement);
// [headers]
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$spreadsheet->save('php://output');
1

There are 1 best solutions below

0
badger179 On

use combination with html tag span followed by space like sample below

<span>&nbsp;</span> <span>&nbsp;</span> <span>&nbsp;</span> <span>&nbsp;</span> 

this example will make 4 spaces