• Resolved jglidewell

    (@jglidewell)


    Has anybody modified this code to work with the XLS option instead of CSV?

    @session_start();
    add_filter( "woe_csv_header_filter", function( $headers) {
    $_SESSION['woe_rows']= array();
    return $headers;
    });
    //save all rows to array
    add_filter( "woe_csv_custom_output_func", function($custom_output,$handle,$data,$delimiter,$linebreak,$enclosure,$is_header) {
    $_SESSION['woe_rows'][] = array_values($data);
    return true;
    },10,7);
    add_action( "woe_csv_print_footer", function($handle, $formatter ){
    $header = reset($_SESSION['woe_rows']);
    foreach($header as $col=>$name) {
    $col_empty = true;
    for($i=1;$i<count($_SESSION['woe_rows']);$i++) {
    if( !empty($_SESSION['woe_rows'][$i][$col])) $col_empty = false;
    }
    if($col_empty)
    for($i=0;$i<count($_SESSION['woe_rows']);$i++) unset($_SESSION['woe_rows'][$i][$col]);
    }
    //done
    foreach($_SESSION['woe_rows'] as $row) fputcsv($handle,$row);
    },10,2);
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello

    Please, submti your current settings as new ticket to https://algolplus.freshdesk.com/ and we’ll adjust this code for XLS.

    You must visit tab “Tools” to get settings as json

    thanks, Alex

    Plugin Author algol.plus

    (@algolplus)

    for whom having same problem . you should use this code

    add_action( 'woe_xls_print_footer', function ($objPHPExcel,$formatter) {
    $data = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
    $top_row = array_shift($data); 
    $col_deleted = 0;
    foreach($top_row as  $col_name=>$title){
      $col_empty = true;
      foreach($data as $row) 
         if(!empty($row[$col_name])) {
           $col_empty = false;
           break; 
         }
       if($col_empty ) {
            $col_idx = PHPExcel_Cell::columnIndexFromString($col_name) -  $col_deleted;
            $objPHPExcel->getActiveSheet()->removeColumnByIndex($col_idx-1);
            $col_deleted++;
       }
    }
    },10,2);
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hiding/Removing empty columns from the export (XLS)’ is closed to new replies.