Skip to content

Instantly share code, notes, and snippets.

@333crist 333crist/phptoexcel.php
Last active Oct 8, 2019

Embed
What would you like to do?
<!--
KRISTIAN DES NATALIS
DEV.#SuperKey
-->
<title>[Blog Kristian] blog.kristiandes.com</title>
<?php
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
ini_set('max_execution_time', 3000);
date_default_timezone_set('Asia/Jakarta');
$lastupdate = date("d-m-Y H:i:s");
?>
<style type="text/css">
.table_zebra {
font-family: tahoma;
color: #555;
border-collapse: collapse;
width: 100%;
border: 1px solid #000;
font-size : 10px;
background-color: #fff;
}
.table_zebra tr th{
background: #0099CC;
color: #fff;
}
.table_zebra, th, td {
padding: 2px 2px;
text-align: center;
}
.table_zebra tr:nth-child(even) {
background-color: #fff;
}
</style>
<script>
window.console = window.console || function(t) {};
</script>
<script>
if (document.location.search.match(/type=embed/gi)) {
window.parent.postMessage("resize", "*");
}
</script>
<body onload="bodyOnloadHandler()" translate="no" >
<h5 style="text-align:left">[Blog Kristian] blog.kristiandes.com sample exporttoexcel_php <?php echo "$lastupdate"; ?></h5>
<table class="table_zebra" bgcolor="#fff" border=1>
<tr>
<td bgcolor="silver" class="medium">Nama</td>
<td bgcolor="silver" class="medium">Alamat</td>
<td bgcolor="silver" class="medium">No tlp</td>
</tr>
<tr>
<td>Kristian Des Natalis</td>
<td>Indonesia</td>
<td>081228432171</td>
</tr>
<tr>
<td>Gabriella Sekar Rara</td>
<td>Indonesia</td>
<td>081228432172</td>
</tr>
<tr>
<td>Gabriell Bagas Kara</td>
<td>Indonesia</td>
<td>081228432173</td>
</tr>
<script>
"use strict";"object"!=typeof window.CP&&(window.CP={}),window.CP.PenTimer={programNoLongerBeingMonitored:!1,timeOfFirstCallToShouldStopLoop:0,_loopExits:{},_loopTimers:{},START_MONITORING_AFTER:2e3,STOP_ALL_MONITORING_TIMEOUT:5e3,MAX_TIME_IN_LOOP_WO_EXIT:2200,exitedLoop:function(o){this._loopExits[o]=!0},shouldStopLoop:function(o){if(this.programKilledSoStopMonitoring)return!0;if(this.programNoLongerBeingMonitored)return!1;if(this._loopExits[o])return!1;var t=this._getTime();if(0===this.timeOfFirstCallToShouldStopLoop)return this.timeOfFirstCallToShouldStopLoop=t,!1;var i=t-this.timeOfFirstCallToShouldStopLoop;if(i<this.START_MONITORING_AFTER)return!1;if(i>this.STOP_ALL_MONITORING_TIMEOUT)return this.programNoLongerBeingMonitored=!0,!1;try{this._checkOnInfiniteLoop(o,t)}catch(e){return this._sendErrorMessageToEditor(),this.programKilledSoStopMonitoring=!0,!0}return!1},_sendErrorMessageToEditor:function(){try{if(this._shouldPostMessage()){var o={action:"infinite-loop",line:this._findAroundLineNumber()};parent.postMessage(o,"*")}else this._throwAnErrorToStopPen()}catch(t){this._throwAnErrorToStopPen()}},_shouldPostMessage:function(){return document.location.href.match(/boomerang/)},_throwAnErrorToStopPen:function(){throw"We found an infinite loop in your Pen. We've stopped the Pen from running. Please correct it or contact support@codepen.io."},_findAroundLineNumber:function(){var o=new Error,t=0;if(o.stack){var i=o.stack.match(/boomerang\S+:(\d+):\d+/);i&&(t=i[1])}return t},_checkOnInfiniteLoop:function(o,t){if(!this._loopTimers[o])return this._loopTimers[o]=t,!1;if(t-this._loopTimers[o]>this.MAX_TIME_IN_LOOP_WO_EXIT)throw"Infinite Loop found on loop: "+o},_getTime:function(){return+new Date}},window.CP.shouldStopExecution=function(o){var t=window.CP.PenTimer.shouldStopLoop(o);return!0===t&&console.warn("[CodePen]: An infinite loop (or a loop taking too long) was detected, so we stopped its execution. Sorry!"),t},window.CP.exitedLoop=function(o){window.CP.PenTimer.exitedLoop(o)};
</script>
<script id="rendered-js">
function download_csv(csv, filename) {
var csvFile;
var downloadLink;
// CSV FILE
csvFile = new Blob([csv], { type: "text/csv" });
// Download link
downloadLink = document.createElement("a");
// File name
downloadLink.download = filename;
// We have to create a link to the file
downloadLink.href = window.URL.createObjectURL(csvFile);
// Make sure that the link is not displayed
downloadLink.style.display = "none";
// Add the link to your DOM
document.body.appendChild(downloadLink);
// Lanzamos
downloadLink.click();
}
function export_table_to_csv(html, filename) {
var csv = [];
var rows = document.querySelectorAll("table tr");
for (var i = 0; i < rows.length; i++) {if (window.CP.shouldStopExecution(0)) break;
var row = [],cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++) {if (window.CP.shouldStopExecution(1)) break;
row.push(cols[j].innerText);}window.CP.exitedLoop(1);
csv.push(row.join(","));
}
// Download CSV
window.CP.exitedLoop(0);download_csv(csv.join("\n"), filename);
}
function bodyOnloadHandler() {
var html = document.querySelector("table").outerHTML;
export_table_to_csv(html, "table<?php echo $tanggalbefore.$tanggalv; ?>.csv");
};
//# sourceURL=pen.js
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.