Skip to content

Commit

Permalink
support col tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ordinaryparksee committed Oct 12, 2020
1 parent 7682c66 commit aebccb9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vaxy/table-to-excel",
"version": "0.0.12",
"version": "0.0.13",
"description": "Convert HTML Table to phpspreadsheet",
"authors": [
{
Expand Down
4 changes: 4 additions & 0 deletions samples/sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<body>
<table style="border-style: thick; margin-top: 14; margin-left: 2.5; font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif">
<caption>Sample Sheet1</caption>
<colgroup>
<col width="30"/>
<col/>
</colgroup>
<thead>
<tr>
<th style="height: 40px; vertical-align: bottom;">Field1</th>
Expand Down
10 changes: 10 additions & 0 deletions src/TableToExcel/TableParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ public static function parse($source)
$sheet->getColumnDimensionByColumn(1)->setWidth($marginLeft);
}

foreach ($table->getElementsByTagName('col') as $colIndex => $col) {
if ($col->hasAttribute('width')) {
if ($tableCss->has('margin-left')) {
$sheet->getColumnDimensionByColumn($colIndex + 2)->setWidth($col->getAttribute('width'));
} else {
$sheet->getColumnDimensionByColumn($colIndex + 1)->setWidth($col->getAttribute('width'));
}
}
}

$rowIndex = $tableRange[0][1] - 1;
$rowspans = [];
foreach ($table->getElementsByTagName('tr') as $tr) {
Expand Down

0 comments on commit aebccb9

Please sign in to comment.