Hey, Would you like to work at Home ?? Just click here No need to pay, just register free and activate your account and get data Entry Work at your Home.

Wednesday, August 15, 2007

Code To Generate Excel Documents - Part 2

<?php
/* Excel Query Output
Allie Micka <allie@pajunas.com> 2/13/02
Outputs an excel spreadsheet for a PEAR query contained in the
variable "$result". If the array "$summaryCols" exists, a
summary row will be printed at the end of the query containing
an excel-calculated summary for that column.

This was generated by using MS Office's "Save as HTML" feature in
Excel, which produces what they call "round trip HTML". By changing
or adding content within their markup you can create a valid Excel
document.
*/

header('Content-Type:application/vnd.ms-excel');?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">

<!--[if gte mso 9]><xml>
<o:DocumentProperties>
<o:Author>Amicka</o:Author>
<o:LastAuthor>Amicka</o:LastAuthor>
<o:Created><?php echo date("Y-m-d\TG:i:s\Z",time())?></o:Created>
<o:LastSaved><?php echo date("Y-m-d\TG:i:s\Z",time())?></o:LastSaved>
<o:Company>pajunas interactive,inc.</o:Company>
<o:Version>9.2720</o:Version>
</o:DocumentProperties>
<o:OfficeDocumentSettings>
<o:DownloadComponents/>
<o:LocationOfComponents HRef="file:msowc.cab"/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<style>
<!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
@page
{margin:1.0in .75in 1.0in .75in;
mso-header-margin:.5in;
mso-footer-margin:.5in;}
tr
{mso-height-source:auto;}
col
{mso-width-source:auto;}
br
{mso-data-placement:same-cell;}
.style0
{mso-number-format:General;
text-align:general;
vertical-align:bottom;
white-space:nowrap;
mso-rotate:0;
mso-background-source:auto;
mso-pattern:auto;
color:windowtext;
font-size:10.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Arial;
mso-generic-font-family:auto;
mso-font-charset:0;
border:none;
mso-protection:locked visible;
mso-style-name:Normal;
mso-style-id:0;}
td
{mso-style-parent:style0;
padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:10.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Arial;
mso-generic-font-family:auto;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:none;
mso-background-source:auto;
mso-pattern:auto;
mso-protection:locked visible;
white-space:nowrap;
mso-rotate:0;}
.xl24
{mso-style-parent:style0;
font-size:8.0pt;
font-weight:700;
font-family:Verdana, sans-serif;
mso-font-charset:0;
text-align:center;
vertical-align:middle;
white-space:normal;}
.xl25
{mso-style-parent:style0;
font-size:8.0pt;
font-family:Verdana, sans-serif;
mso-font-charset:0;
white-space:normal;}
.xl26
{mso-style-parent:style0;
font-size:8.0pt;
font-family:Verdana, sans-serif;
mso-font-charset:0;
background:white;
mso-pattern:auto none;
white-space:normal;}
-->
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name><?php echo $reportTitle ?></x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
<x:HorizontalResolution>600</x:HorizontalResolution>
<x:VerticalResolution>600</x:VerticalResolution>
</x:Print>
<x:Selected/>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
<x:ActiveCol>4</x:ActiveCol>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>11340</x:WindowHeight>
<x:WindowWidth>17055</x:WindowWidth>
<x:WindowTopX>120</x:WindowTopX>
<x:WindowTopY>30</x:WindowTopY>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml><![endif]-->
</head>
<body link=blue vlink=purple leftmargin=0 topmargin=0>

<table x:str border=0 cellpadding=0 cellspacing=0 style='border-collapse:
collapse;table-layout:fixed;'>
<?php // <col width=64 span=4 style='width:48pt'>$summaryValues = Array();$summaryCols = isset($summaryCols) ? $summaryCols : Array();

while (
$row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
// print column labels:
if(!isset($column_labels_printed)) {
$xlCols = range(65,90);
echo
'<tr height=28 style=\'height:21.0pt\'>';
foreach(
$row as $col =>$val) {
//print label header
echo '<td height=28 class=xl24 style=\'height:21.0pt;\'>',
ucwords(str_replace('_',' ',strtolower($col))),
'</td>';

// establish information needed for column summary
$columnArray[] = $col;
$xlCol = chr(array_shift($xlCols));
if(
in_array($col,$summaryCols)) {
$summaryValues[$col] = Array(
xlCol => $xlCol,
start => 2,
end =>1,
total =>0);
}
}
echo
'</tr>';
$column_labels_printed = true;
}
//print values
echo '<tr height=29 style=\'height:21.75pt\'>';
foreach(
$row as $col => $val) {
echo
'<td height=29 class=xl25 align=right style=\'height:21.75pt;
width:48pt\''
;
if(
is_numeric($val)) { echo ' x:num'; }
echo
'>',$val,'</td>';

if(
in_array($col,$summaryCols)) {
$summaryValues[$col][total] += $val;
$summaryValues[$col][end] +=1;
}
}
echo
'</tr>';
}
//print summary columns
// print_r($summaryValues);
if(count($summaryValues)) {
foreach(
$columnArray as $col) {
echo
'<td align=right';
if(isset(
$summaryValues[$col])) {
echo
' x:num x:fmla="=SUM('.$summaryValues[$col][xlCol].$summaryValues[$col][start].':'.$summaryValues[$col][xlCol].$summaryValues[$col][end].')">'.$summaryValues[$col][total].'</td>';
} else {
echo
'>&nbsp;</td>';
}
}

if(!isset(
$column_labels_printed)) {
echo
'No Results.';
}
/*<tr height=17 style='height:12.75pt'>
<td height=17 colspan=2 style='height:12.75pt;mso-ignore:colspan'></td>
<td align=right x:num x:fmla="=SUM(C2:C7)">56308.71</td>
<td align=right x:num x:fmla="=SUM(D2:D7)">446.49</td>
</tr>
<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
<td width=64 style='width:48pt'></td>
</tr>
<![endif]>*/
?></table>

</body>

</html>

No comments:

Your Ad Here