简体   繁体   中英

PHPExcel missing text boxes

I need to open a existing xlsx file, that contains text boxes (those created with the predefined option like circles, squares, etc), and I need to write just behind this objects (they are transparent).

The code bellow does everything fine, except that downloads the new file without the boxes.

if(file_exists("app/file.xlsx")){

        $objTpl = PHPExcel_IOFactory::load("app/file.xlsx");
        $objTpl->setActiveSheetIndex(1);

        $objTpl->getActiveSheet()->setCellValue('A1', 'x');
        $objTpl->getActiveSheet()->setCellValue('A2', 'y');
        $objTpl->getActiveSheet()->setCellValue('A3', 'z');

        $filename = 'new_file.xlsx';
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="'.$filename.'"');
        header('Cache-Control: max-age=0');

        $objWriter = PHPExcel_IOFactory::createWriter($objTpl, 'Excel2007');
        ob_end_clean();
        $ret = $objWriter->save('php://output');

        exit;
    }

you can probably do this via the COM dotnet php module

simply open the xlsx file:

$excel = new COM("Excel.Application") or die ("Could not initialise Object.");
            $excel->Visible       = 1;
            $excel->DisplayAlerts = 0;
            $Workbook = $excel->Workbooks->Open($file) or die("ERROR: Unable to open " . $file . "!\r\n");
            $Worksheet = $Workbook->ActiveSheet;

and from here on out alter your file and then use the saveas function. its all +- well documented in the developers doc from microsoft: https://msdn.microsoft.com/EN-US/library/office/ff198122.aspx

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