摘要:[PHP]列印或輸出Excel
PHP 利用 JavaScript 列印指定 DIV 的 HTML 畫面
function JavaScript_Code()
{
//畫面內使用 CSS 排版及使用 JavaScript
function printPartOfPage(elementId) {
var printContent = document.getElementById(elementId);
var windowUrl = 'about:blank';
var printWindow = window.open(windowUrl, "", 'left=50000,top=50000,width=0,height=0,status=no');
var str = "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'><html><head><title></title>";
str = str + "<style type='text/css' media='print'>";
str = str + "CSS CODE";
str = str + "</style><script type='text/javascript'>";
str = str + "</script>";
str = str + "</head><body>";
printWindow.document.writeln(str);
printWindow.document.write(printContent.innerHTML);
var str2 = "</body></html><script type='text/javascript'>";
str2 = str2 +"JavaScript_Code";
str2 = str2 + "</script>";
printWindow.document.writeln(str2);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
}
function HTML_Code()
{
<input class="reportprint" type="button" value="" onclick="printPartOfPage('DIVID');"/>
}
PHP 使用 Form Post 將指定DIV畫面輸出至 Excel(xls)
function HTML_Code()
{
<form action="../exportfunction/xls_row.php" method="post"
onsubmit='$("#datatodisplay").val( $("div").append( $(".ReportTable").eq(0).clone() ).html() )'>
<input type="hidden" id="datatodisplay" name="datatodisplay">
<input class="exportxls" type="submit" value=""/>
<div>
<!--欲輸出之HTML-->
</div>
}