PHP Excel download - Downloaded file looks has garbage -
when try download file (not displaying in browser) file opens looks corrupted. when save file in server , open later file has contents. code works in windows. have problem when move linux. code using below.
if (strtoupper(gst_excel_file_format) == "xls") { $filename = dol_document_root."/gst/template/gstr1_excel_workbook_template-v1.5.xls"; } elseif (strtoupper(gst_excel_file_format) == "xlsx") { $filename = dol_document_root."/gst/template/gstr1_excel_workbook_template-v1.5.xlsx"; } $fileextension= pathinfo($filename, pathinfo_extension); $inputfiletype = phpexcel_iofactory::identify($filename); $objreader = phpexcel_iofactory::createreader($inputfiletype); $objreader->setloadallsheets(); $objphpexcel = $objreader->load($filename); $ii= 8; $row = 5; // 1-based index $objphpexcel->setactivesheetindexbyname("b2b"); //set first sheet active $objectlines = $resultset[0]; foreach ($objectlines $line) { $col = 0; { $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow( $col, $row, $line->gstin); $col++; $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $line->invoiceno); $col++; $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $line->invoicedate); $col++; $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $line->totalvalue); $col++; $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $line->pos); $col++; $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $line->reverse_flag); $col++; $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $line->invoice_type); $col++; $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $line->ecommgst); $col++; $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $line->rate); $col++; $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $line->taxable_value); $col++; $objphpexcel->getactivesheet()->setcellvaluebycolumnandrow($col, $row, $line->cess); } $row++; } $objwriter = phpexcel_iofactory::createwriter($objphpexcel, $inputfiletype); $outputfilename=mt_rand(1,100000).".".$fileextension; header('content-type: application/vnd.ms-excel'); header('content-disposition: attachment;filename="'.$outputfilename.'"'); header('cache-control: max-age=0'); $objwriter->save('php://output');
Comments
Post a Comment