Created
September 24, 2014 07:17
-
-
Save goldalworming/169117bfcb31c14024da to your computer and use it in GitHub Desktop.
php download to excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function allitemap($date){ | |
header('Access-Control-Allow-Origin:*'); | |
ini_set('memory_limit','1000M'); | |
$alldata = $this->mod_detailaraccounting->get_allitemap($date)->result_array(); | |
$data['data'] = $alldata; | |
$data['filename'] = 'allitem-'.$date; | |
$data['array_header'] = array( | |
'GPART' => 'Partner', | |
'BU_NAME' => 'Nama OLO', | |
'NO_INVOICE' => 'No. Invoice', | |
'INVOICE_GROUP' => 'Invoice Group', | |
'DOC_NO' => 'Doc. No.', | |
'TGL_CLEARING' => 'Clearing Date', | |
'CLEARING_DOC' => 'Clearing Doc', | |
'POSTING_DATE' => 'Posting Date', | |
'INVOICE_DATE' => 'Invoice Date', | |
'DUE_DATE' => 'Due Date', | |
'REC_KEY' => 'Rec. Key', | |
'GL_ACCT' => 'G/L acct', | |
'CURR_USD' => 'Doc Cur', | |
'SALDODOC' => 'Saldo Akhir (DOC) ', | |
'CURR_IDR' => 'Local Cur', | |
'SALDOLOC' => 'Saldo Akhir (LOCAL) ' | |
); | |
$this->load->view('vexcel', $data); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Pragma: public"); | |
header("Expires: 0"); | |
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
header("Content-Type: application/force-download"); | |
header("Content-Type: application/octet-stream"); | |
header("Content-Type: application/download"); | |
header("Content-Disposition: attachment;filename=".$filename.".xls "); | |
header("Content-Transfer-Encoding: binary "); | |
?> | |
<?php function is_decimal($val){ | |
return is_numeric($val)&& floor($val)!=$val; | |
}?> | |
<table id="alifRahman" border="1"> | |
<thead> | |
<tr> | |
<?php | |
//print_r($data); | |
$arrayhide = array(); | |
$arraynoformat = array(); | |
$i = 0; | |
foreach (array_keys($data[0]) as $tmp) { | |
if ($tmp=='NOMORURUT'){$tmp='NO';} | |
//jika ada kata no pots atau no fastel | |
//maka dimasukan ke arraynoformat | |
if (preg_match("/\bgpart\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bno_invoice\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bdoc_no\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bgl_acct\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bsaldodoc\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bsaldoloc\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bopbel\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bhkont\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bbudat\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bbldat\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
} | |
// elseif (preg_match("/\bbetrw\b/i", $tmp)) { | |
// array_push($arraynoformat, $i); | |
// } | |
// elseif (preg_match("/\bbetrh\b/i", $tmp)) { | |
// array_push($arraynoformat, $i); | |
// } | |
elseif (preg_match("/\buecpu\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bzzcis_invdocno\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\binvdate\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bfaedn\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bzznpr\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bzzidrev\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bzznper\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
}elseif (preg_match("/\bzzcca\b/i", $tmp)) { | |
array_push($arraynoformat, $i); | |
} | |
if ($tmp=='VBUND'){ | |
array_push($arrayhide, $i); | |
} | |
elseif ($tmp=='GL_KLAS'){ | |
array_push($arrayhide, $i); | |
} | |
elseif ($tmp=='AUGST'){ | |
array_push($arrayhide, $i); | |
} | |
elseif ($tmp=='HKONTA'){ | |
array_push($arrayhide, $i); | |
} | |
else{ | |
if (isset($array_header) && array_key_exists($tmp, $array_header)){ | |
print '<th bgcolor="#ADD8E6">'.str_replace("_", " ", $array_header[$tmp]).'</th>'; | |
}else{ | |
print '<th bgcolor="#ADD8E6">'.str_replace("_", " ", $tmp).'</th>'; | |
} | |
} | |
$i++; | |
} | |
?> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
if(count($data)>0){ | |
for($i=0;$i<count($data);$i++){ | |
print "<tr>"; | |
$j = 0; | |
$tmp = array_values($data[$i]); | |
foreach ( $tmp as $val) { | |
$align='left'; | |
//jika $j tidak ada di $arraynormat maka tidak pakai format | |
if (in_array($j, $arraynoformat)){ | |
//tidak perlu diberi format | |
} | |
else{ | |
if (is_decimal($val)){$val =number_format($val,2,',','.');$align='right';} | |
elseif (is_numeric($val)) { | |
$val =number_format($val,0,',','.');$align='right'; | |
} | |
} | |
if (in_array($j, $arrayhide)){ | |
//tidak perlu tulis apa2; | |
} | |
else{ | |
print "<td style='align:{$align}'>$val</td>"; | |
} | |
$j++; | |
} | |
print "</tr>"; | |
} | |
}else{ | |
?> | |
<tr> | |
<td>-</td> | |
<td>-</td> | |
<td>-</td> | |
<td>-</td> | |
<td>-</td> | |
<td>-</td> | |
<td>-</td> | |
</tr> | |
<?php | |
} | |
?> | |
</tbody> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment