i can't excel file request. why?
my code:
angular:
//angular service //used export button this.exportexcel = function($scope){ return $http({ method: "post", url: "/home/ppeconfigperiod/getflowlisttodatatable", headers: { 'content-type': 'application/json; charset=utf-8' }, data: { ppeflowselectcon : $scope.ppeflowselectcon, periodid : $scope.currentperiod.id, staff : $scope.staff } }).success(function(data){ if(data != null){ //location.href=data; } }); }
php:
public function getflowlisttodatatable() { $requesturl = apiurls::getflowlisttodatatable; $data = json_decode(file_get_contents("php://input")); $ppeflowselectcon = $data->ppeflowselectcon; $filename = "ppetrack_" . $data->staff->loginname . "_" . date('y-m-d'); $postarray = array( "periodid" => $data->periodid ); $result = servicepost($requesturl, $postarray, $ppeflowselectcon); $newresult = array(); foreach( $result $key => $value){ $newresult = get_object_vars($value); } exportexcel($newresult, array(), $filename); //$this->ajaxreturn($result); } function exportexcel($data=array(), $title=array(), $filename='report'){ header("content-type:application/octet-stream"); header("accept-ranges:bytes"); header("content-type:application/vnd.ms-excel"); header("content-disposition:attachment;filename=".$filename.".xls"); header("pragma: no-cache"); header("expires: 0"); if (!empty($title)){ foreach ($title $k => $v) { $title[$k]=iconv("utf-8", "gb2312",$v); } $title= implode("\t", $title); echo "$title\n"; } if (!empty($data)){ foreach($data $key=>$val){ foreach ($val $ck => $cv) { $data[$key][$ck]=iconv("utf-8", "gb2312", $cv); } $data[$key]=implode("\t", $data[$key]); } echo implode("\n",$data); }
and webapi:
[httppost] [route("getflowlisttodatatable")] public datatable getflowlisttodatatable(ppeflowselectcon selcon, guid periodid) { return new configperiodfacade().getflowlisttodatatable(selcon, periodid); }
thanks.
first of all,your code messy!try using comments can understand doing.
connecting excel file done odbc_connect
.like this:
$excelfile = realpath('c:/exceldata.xls'); //the path of excel file stored in variable $exceldir = dirname($excelfile); $connection = odbc_connect("driver={microsoft excel driver (*.xls)};driverid=790;dbq=$excelfile;defaultdir=$exceldir" , '', '');
this article familiar odbc_connect()
.
Comments
Post a Comment