简体   繁体   中英

PHPExcel ReadFilter doesnt work

I'm still stuck with symfony2 and phpexcel..

First I don't know why my HTML writer doesn't generate <thead></thead> tags..

I don't understand why blanks columns still displaying as you can see on this screenshot, a ReadFilter is applied:

I just want to load the first 13 columns:

在此处输入图片说明

public function showClientAction()
{

$excel = glob(''.path.'\\'.tofile.'\\'.$file.'.{xlsx,xls,xlsm,xlsm.ink}', GLOB_BRACE);

$filterSubset = new \PHPExcel_Reader_DefaultReadFilter('A','N');

$objReader = \PHPExcel_IOFactory::createReaderForFile($excel[0]);
$objReader->setReadFilter($filterSubset);


/**  Read the list of worksheet names and select the one that we want to load  **/
$worksheetList = $objReader->listWorksheetNames($excel[0]);
$sheetname = $worksheetList[0];

/**  Advise the Reader of which WorkSheets we want to load  **/
$objReader->setLoadSheetsOnly($sheetname);

$objPHPExcel = $objReader->load($excel[0]);

$writer = \PHPExcel_IOFactory::createWriter($objPHPExcel, "HTML");
$writer->generateSheetData();
$writer->generateStyles();

return $this->render('SocietyPerfclientBundle:Default:testexcel.html.twig', array(
    'excelHtml'=>$writer
));
}

My Filter :

class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter {

    public function __construct($fromColumn, $toColumn) {
        $this->columns = array();
        $toColumn++;
        while ($fromColumn !== $toColumn) {
            $this->columns[] = $fromColumn++;
        }
    }

    public function readCell($column, $row, $worksheetName = '') {
        // Read columns from 'A' to 'AF'
        if (in_array($column, $this->columns)) {
            return true;
        }
        return false;
    }
}

I can't understand why these blank column are here...

ReadFilter is not working with HTML Writer ?

I can't just do :

.column14 { display:none;!important;}
.column15 { display:none;!important;}
.column16 { display:none;!important;}
.column17 { display:none;!important;}
etc...

Because I use jQuery Plugin "floatThead" to create a fixed <thead></thead>

In my view :

              var table = $('#sheet0'); // select the table of interest
              var thead = $('<thead/>').prependTo(table);
 // create <thead></thead>


          table.find('tbody tr.row0').appendTo(thead);


              // Now the table is ready to have your chosen method applied to fix the position of the thead.
              $('table.sheet0').floatThead({
                  position: 'fixed',
                  index: '8',
                  overflow: 'auto'
          });

Please help me..

i think :

$this->columns[] = $fromColumn++;

do nothing .

try :

for ($i = $fromColumn; $i != $toColumns ; $i++)
    {
        $this->columns[$i]=$i;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM