<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body><div style="text-align: left;">
> <br>> I'll take a look at the snipit you provided. Do you have the original <br>> code handy somewhere, and some time to dig it out for me?<br>> <br>> ~ ~ Dave<br>> <br>> J. Meijer wrote:<br>> > <br>> > <br>> > Dave,<br>> > <br>> > I have a script that sums row and sums columns putting in a markup in <br>> > the summing row/column and quite a bit smarter then the code below. <br>> > Haven't looked at it in a while.<br>> > <br><br><br>Below you'll find the relevant extract of the script that inserts itself between table markup and the pmwiki table function. <br><br>It
internally reconstructs the table from data within <td> tags. So
it's able to do calculations on it. Hunt for embedded directives like
(:rowtotal:) and (:rowcount:). The difference between the 2 is that
rowtotal rounds to 2 digits (money format), while rowcount expects to
work with integers. <br><br>The recipy could be easily generalized, it was just a quick hack. The number of digits should at least be a parameter. <br><br>We could do much better! <br><br>/jm<br><br><a href="http://applicationmain_11.08.0100.0011.aspx/?culture=en-US&hash=-822026028#" id="EC_EditMessageSendMessageCmd" class="EC_Command FireAnt_Command Web_Bindings_Base ToolBarListHover ButconPressed" target="_blank">
<span></span></a><br><br> # redine ||cell||, ||!header cell||, ||!caption!|| markup<br>Markup('^||||', 'block', <br> '/^\\|\\|.*\\|\\|.*$/e',<br> "TotalFormatTableRow(PSS('$0'))");<br><br> # reset totals for use between tables<br>Markup('resettotals','^||||',<br> '/[(]:resettotals:[)]/e',<br> 'PZZ($GLOBALS["ColumnTotals"]=array())');<br><br><br><br>function TotalFormatTableRow($x) {<br> global $ColumnTotals;<br> $x=FormatTableRow($x);<br> $y=strip_tags($x,'<td>');<br> if(!preg_match_all('/>(.*?)<\/td>(?:<td|$)/mi',$y,$m)) return $x;<br> $tot=0;<br> foreach($m[1] as $i=>$n) {<br> if(substr($n,-3,1)==',') # undo locale for money format<br> $n=str_replace(array('.',',','%+%'),array('%+%','.',','),$n);<br> if(is_numeric($n)) {<br> $tot+=$n;<br> $ColumnTotals[$i]+=$n;<br> }<br> }<br> foreach($m[1] as $i=>$c) {<br> if(false!==strpos($c,'(:coltotal:)')) # presume money format<br> $x=substr_replace($x,sprintf("%01.2f", $ColumnTotals[$i]),strpos($x,'(:coltotal:)'),12);<br> elseif(false!==strpos($c,'(:colcount:)')) # presume integers<br> $x=substr_replace($x,$ColumnTotals[$i],strpos($x,'(:colcount:)'),12);<br> else<br> continue;<br> $tot+=$ColumnTotals[$i];<br> }<br> foreach($m[1] as $i=>$c) <br> if(false!=strpos($c,'(:rowtotal:)')) <br> $ColumnTotals[$i]+=$tot;<br> $x=str_replace('(:rowtotal:)',sprintf("%01.2f", $tot),$x); # intended for money formats<br> $x=str_replace('(:rowcount:)',$tot,$x); # intended for integers<br> $c=1;<br> $x=preg_replace('/[(]:coltotal:[)]/mie','sprintf("%01.2f", $ColumnTotals[$c++])' ,$x);<br><br> return $x; <br>}<br><br></div><br><br /><hr />Get into the holiday spirit, chat with Santa on Messenger. <a href='http://imagine-windowslive.com/minisites/santabot/default.aspx?locale=en-us' target='_new'>Ho-Ho-Ho!</a></body>
</html>