yourilima / php-excel-reader

Automatically exported from code.google.com/p/php-excel-reader
0 stars 0 forks source link

Code to dump only part of sheet or all the sheet #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I added 4 more prams to optionally cut out only part of a sheet in a dump.

it adds nice functionality to simply display only part of a sheet.

---snip---

// DUMP AN HTML TABLE OF THE ENTIRE OR PART OF XLS DATA
    // =========================================
    function
dump($row_numbers=false,$col_letters=false,$sheet=0,$table_class='excel',$startr
ow=1,$endrow=0,$startcol=1,$endcol=0)
{
        $out = "<table class=\"$table_class\" cellspacing=0>";
        if ($endcol == 0 ){
                $endcol = $this->colcount($sheet);
        }
        if($endrow ==0){
            $endrow = $this->rowcount($sheet);
        }
        if ($col_letters) {
            $out .= "<thead>\n\t<tr>";
            if ($row_numbers) {
                $out .= "\n\t\t<th>&nbsp</th>";
            }

            for($i=$startcol;$i<=$endcol;$i++) {
                $style = "width:" . ($this->colwidth($i,$sheet)*1) . "px;";
                if ($this->colhidden($i,$sheet)) {
                    $style .= "display:none;";
                }
                $out .= "\n\t\t<th style=\"$style\">" .
strtoupper($this->colindexes[$i]) . "</th>";
            }
            $out .= "</tr></thead>\n";
        }

        $out .= "<tbody>\n";

        for($row=$startrow;$row<=$endrow;$row++) {
            $rowheight = $this->rowheight($row,$sheet);
            $style = "height:" . ($rowheight*(4/3)) . "px;";
            if ($this->rowhidden($row,$sheet)) {
                $style .= "display:none;";
            }
            $out .= "\n\t<tr style=\"$style\">";
            if ($row_numbers) {
                $out .= "\n\t\t<th>$row</th>";
            }
            for($col=$startcol;$col<=$endcol;$col++) {
                // Account for Rowspans/Colspans
                $rowspan = $this->rowspan($row,$col,$sheet);
                $colspan = $this->colspan($row,$col,$sheet);
                for($i=0;$i<$rowspan;$i++) {
                    for($j=0;$j<$colspan;$j++) {
                        if ($i>0 || $j>0) {
                            $this->sheets[$sheet]['cellsInfo'][$row+$i][$col+$j]['dontprint']=1;
                        }
                    }
                }
                if(!$this->sheets[$sheet]['cellsInfo'][$row][$col]['dontprint']) {
                    $style = $this->style($row,$col,$sheet);
                    if ($this->colhidden($col,$sheet)) {
                        $style .= "display:none;";
                    }
                    $out .= "\n\t\t<td style=\"$style\"" . ($colspan > 1?"
colspan=$colspan":"") . ($rowspan > 1?" rowspan=$rowspan":"") . ">";
                    $val = $this->val($row,$col,$sheet);
                    if ($val=='') { $val="&nbsp;"; }
                    else {
                        $val = htmlentities($val);
                        $link = $this->hyperlink($row,$col,$sheet);
                        if ($link!='') {
                            $val = "<a href=\"$link\">$val</a>";
                        }
                    }
                    $out .= "<nobr>".nl2br($val)."</nobr>";
                    $out .= "</td>";
                }
            }
            $out .= "</tr>\n";
        }
        $out .= "</tbody></table>";
        return $out;
    }

---snip---

Original issue reported on code.google.com by christop...@zionsbancorp.com on 30 Mar 2009 at 9:06

GoogleCodeExporter commented 9 years ago
I was thinking of this same thing last night. 
I think what I want to do is to pass an array of key/value parameters, rather 
than
continuing to add optional parameters to the method signature. This way I could 
keep
adding more options without making it too confusing.

I also wanted to add the option to only output specific formatting, so if the 
XLS has
borders and colors but all you want is the data displayed, you can choose to 
ignore
some formatting options.

I think I'm going to do a 2.21 release hopefully some time this week, so I'll
probably add these enhancements to that release.

Original comment by matthew....@gmail.com on 30 Mar 2009 at 9:14

GoogleCodeExporter commented 9 years ago
Is there any way to retrieve the total number of sheets in the XLS file? Sorry 
to
post here but I can't see it anywhere in your doc.

Original comment by neilgpar...@gmail.com on 8 Apr 2009 at 11:46

GoogleCodeExporter commented 9 years ago
Is there any way to add an array that holds the columns to display instead of a 
range? 

Original comment by EdmondTh...@gmail.com on 30 May 2013 at 10:33