how to duplicate complex content from my template

Topics: Developer Forum, User Forum
May 22, 2014 at 3:07 AM
hi,all
my template execel5 file have some complex contents, such as many merge cells, borders, fonts.
i want to copy from template file .
i use the call :
        $destAddr = "A" . $startLine . ":F" . $endLine;
        $sheet->duplicateStyle ( $sheet->getStyle ( 'A1:F160' ), $destAddr );
but i found the merge cells not working, so i have to merge everything.

how to solve the problem?

thanks a lot!
Coordinator
May 22, 2014 at 8:42 AM
Merged cells isn't style related, it's structural, so duplicating a style won't have any affect on merged cells, that needs to be done manually
May 23, 2014 at 1:04 AM
my temporary solution is to clone worksheet.
    $inputFileType = 'Excel5';
    
    $objReader = PHPExcel_IOFactory::createReader ( $inputFileType );   
    $objPHPExcel = $objReader->load ( $tempfile );  
    $objPHPExcel->getProperties ()->setCreator ( "wss" )->setLastModifiedBy ( "wss" )->setTitle ( "Report Print File" )->setSubject ( "Report Print File" )->setDescription ( "Report Print File." )->setKeywords ( "office 2003 php" )->setCategory ( "wss" );
    $objPHPExcel->setActiveSheetIndex ( 0 );
    $sheetTemplate = $objPHPExcel->getActiveSheet ();
    
    // clone sheet
    for($current = 1; $current <= $total; $current ++) {
        $sheetIndex = $current - 1;

        if($current > 1){
            $sheet = clone $sheetTemplate;
            $sheet->setTitle ( "".$sheetIndex );
            // A4
            $sheet->getPageSetup ()->setOrientation ( PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT );
            $sheet->getPageSetup ()->setPaperSize ( PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4 );
            $sheet->getPageSetup ()->setHorizontalCentered ( true );
            // add new sheet
            $objPHPExcel->addSheet($sheet, $sheetIndex);
        }else{
            $sheetTemplate->setTitle ( "".$sheetIndex );
        }
    }

    $objWriter = PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel5' );
    $objWriter->save ( $outputfile );
    
    if (file_exists ( $outputfile )) {
        header ( 'Pragma: public' );
        header ( 'Expires: 0' );
        header ( 'Content-Encoding: none' );
        header ( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
        header ( 'Cache-Control: public' );
        header ( 'Content-Type: application/vnd.ms-excel; charset=utf-8' );
        header ( 'Content-Disposition: attachment; filename=' . time () . pathinfo ( $outputfile, PATHINFO_BASENAME ) );
        header ( 'Content-Transfer-Encoding: binary' );
        header ( 'Content-Length: ' . filesize ( $outputfile ) );
        readfile ( $outputfile );
    } else {
        echo '<script>alert(\'export error, file not exists!\')</script>';
    }
any suggestions?