Oct 22
I have recently discarded my usual method of generating Excel documents using PHP. Before this, I used to write XML files and even before that, uses PHPExcel library.
My good friend just pointed out that its better to save the file as HTML but write the extension as XLS instead.
However, there are some complications. To define the cell’s number format, you need to use CSS. Here’s what you need to put inside the class.
Styling Excel cells with mso-number-format
mso-number-format:”0″ NO Decimals
mso-number-format:”0\.000″ 3 Decimals
mso-number-format:”\#\,\#\#0\.000″ Comma with 3 dec
mso-number-format:”mm\/dd\/yy” Date7
mso-number-format:”mmmm\ d\,\ yyyy” Date9
mso-number-format:”m\/d\/yy\ h\:mm\ AM\/PM” D -T AMPM
mso-number-format:”Short Date” 01/03/1998
mso-number-format:”Medium Date” 01-mar-98
mso-number-format:”d\-mmm\-yyyy” 01-mar-1998
mso-number-format:”Short Time” 5:16
mso-number-format:”Medium Time” 5:16 am
mso-number-format:”Long Time” 5:16:21:00
mso-number-format:”Percent” Percent – two decimals
mso-number-format:”0%” Percent – no decimals
mso-number-format:”0\.E+00″ Scientific Notation
mso-number-format:”\@” Text
mso-number-format:”\#\ ???\/???” Fractions – up to 3 digits (312/943)
mso-number-format:”\0022£\0022\#\,\#\#0\.00″ £12.76
mso-number-format:”\#\,\#\#0\.00_ \;\[Red\]\-\#\,\#\#0\.00\ ”
2 decimals, negative numbers in red and signed
(1.56 -1.56)
Courtesy of http://cosicimiento.blogspot.com/2008/11/styling-excel-cells-with-mso-number.html
Jul 18
I am currently learning WordPress in order to cut down costs on corporate profile websites. Like all learning processes, it is a headache. Don’t get me wrong, WordPress is awesome, and I meant that in every technical way.
But I’ve been cracking my head on a lot of basic things I used to be able to do without a pause, now taking me few half-hours to figure out. Here’s one to help you out.
$category = get_the_category();
function get_category_list($cat_id) {
$category = get_category($cat_id);
$cat_list[] = $cat_id;
for ($i = 0; $i < 10; $i++) {
if ($category->category_parent == 0) break;
$category = get_category($category->category_parent);
$cat_list[] = $category->cat_ID;
}
return $cat_list;
}
Jun 16
Horrible performance on the system. Benchmarking has been done and results aren’t really favorable. Need to learn how to optimize the resources. Started using mysql_close and mysql_free_result to free up some of the mysql bottlenecks. Also, some gzip compression…?
[code type=php]
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); //start compressing the page if possible
[/code]
And some links to help on optimizing MySQL calls:
http://www.ehow.com/how_5088433_optimize-mysql-tables-performance.html
http://forge.mysql.com/wiki/Top10SQLPerformanceTips
Wondered why I never used REPLACE or ON DUPLICATE KEY UPDATE before. This could be useful. Hmm.
Ciao.
Jun 11
http://www.cssgallerysubmission.com/css-gallery-list/
Ciao!
May 30
Here’s a simple form validation you can use.
It’s pretty simple, since I used loop and declared the required fields upfront.
$required_fields = array('address', 'applicant_passno', 'signatory','fgender');
$required_fields_description = array('Address', 'Applicant IC Number', 'Signatory Option','First applicant gender');
$count = 0;
foreach($required_fields as $fields) {
if ($_POST[$fields] == '') $error_check .= "You need to enter field '".$required_fields_description[$count]."'. Go back. <br />";
$count++;
}
>if ($error_check != "") {
die( "<h1>Error Found:</h1>".$error_check."<br /> Go back.");
}
May 01
Heh, just installed Flock and tried the blog post feature from the browser!
Ciao.
Mar 22
I am currently working on a Fund/Asset Management System and just found out about this – Math in Javascript sucks.
http://www.astonisher.com/archives/bugnet/alerts/bugalert9298.html
The link above will explain more about this error. Javascript apparently is not accurate for math calculations, leaving behind very insignificant (but very real) errors like
81.66 * 15 = 1224.8999999999999 //instead of the right answer = 1224.9
– which is very much disrupting my project’s workflow and accuracy.
It causes a very complicated ‘it’s-not-my-fault’ explanation to the client. The solution is always rounding up to an insignificant decimal point like
variable.toFixed(6)
to properly reformat the numbers to the correct value.
This also happens to calculations that supposed to return 0 but returned 0.00000000000000001 instead.
I suggest avoid using Javascript altogether to avoid the hassle, stick to PHP to crunch out your numbers.
Mar 10
Learned a cool thing today. I wanted to match 2 strings and see how much do they match rather than having the usual == Yes/No match comparison. This method is very useful for detecting matches in names, addresses and such where data entered usually differs by dots, commas or spaces. You have to strip everything into numbers and string first, though, to get more accurate data.
Here’s how you do it:
$str1 = ereg_replace("[^A-Za-z0-9]", "", $str1);
$str2 = ereg_replace("[^A-Za-z0-9]", "", $str2);
similar_text($str1, $str2, $percent);
Chao~
Mar 02
Problem:
I have a long winding table that exceeds 3x page size. But I don’t want everything squeezed up since it causes the height to be abnormally tall. Specifying a specific width is too much hassle and it is not compatible with my hide-show-column feature. When I hide all the columns, leaving 3 columns per se, the width retains.
Solution:
Put this in TD element CSS declaration:
white-space: nowrap;
Viola. Long thin column for each data.
Feb 24
Hiding ID and Class is different in Scriptaculous. Hiding ID is pretty straightforward, but I just learned how to hide class, so I’ll post it up again.
Here’s how it’s done.
ID:
$('id_of_the_item').hide();
CLASS:
$$('.class').each(Element.hide);
Been looking for this since forever. Useful to hide columns in tables.
Also, this is a new addition:
Using function inside Class manipulation-
$$('.textbox').each(function(e){ e.value = 100; } ); //changing all the value of class .textbox items to 100
While we’re on the same note, here’s how to quickly make a select-all checkbox function:
Add this into your master checkbox onclick
onclick="$('.confirm').each(function(e){ e.checked = $('children_checkbox').checked })" //e is the master checkbox
Chiao!