MarkBaker,
Thanks for your response.
I wrote a test PHP script to test curreny fornat for Excel5 and Excel2007. And I create TestExcel 5.xls and TestExcel2007.xlsx for test.
In each Exel file, I sent CELL 'I5' with currency format. I tested with all currency foramt: -1234, 1234 with red color, (1234), and (1234) woth red color.
The results tell me for Excel5, all returned formatcode are correct. For Excel2007, if format is -1234 or 1234 with red color, return correct format code. But, if set as
(1234) or (1234) woth red color, it returns "General".
Becasue I can not attahced the excel files,I copy part of the out put in the bottom. Please notes that first section of the out put is the test result for Ecel5, second is for Excel2007.
<?php //ShowFormatCode.php
session_start();
$nodtcol = array();
$dtdex = array();
$highestRow = 8;
echo 'Only show first 7 rows---------------------<br>';
function get_col_letter($num){
?>
Part of the out put as shown:
inputFileName***./upload/TestExcel5.xls***
Excel type:Excel5
......
End 4th row-----------------------------------------------------
A5GeneralvalueG00000759
B5GeneralvalueF
C5GeneralvalueUMTA
D5GeneralvalueUNNY-03-0344
E5Generalvalue14.08.80
F5Generalvalue3456
G5#,##0.00value61438180.11
H5#,##0.00value61438180.11
I5**"$"#,##0_);[Red]("$"#,##0)value-1234.77**
J5Generalvalue****
K5Generalvalue****
End 5th row-----------------------------------------------------
------------------------*******----------------------------
inputFileName./upload/TestExcel2007.xlsx
Excel type:Excel2007
............
A5GeneralvalueG00000759
B5GeneralvalueF
C5GeneralvalueUMTA
D5GeneralvalueUNNY-03-0344
E5Generalvalue14.08.80
F5Generalvalue3456
G5#,##0.00value61438180.11
H5#,##0.00value61438180.11
I5Generalvalue1234.77
J5Generalvalue****
K5Generalvalue****
End 5th row-----------------------------------------------------
Thanks for your response.
I wrote a test PHP script to test curreny fornat for Excel5 and Excel2007. And I create TestExcel 5.xls and TestExcel2007.xlsx for test.
In each Exel file, I sent CELL 'I5' with currency format. I tested with all currency foramt: -1234, 1234 with red color, (1234), and (1234) woth red color.
The results tell me for Excel5, all returned formatcode are correct. For Excel2007, if format is -1234 or 1234 with red color, return correct format code. But, if set as
(1234) or (1234) woth red color, it returns "General".
Becasue I can not attahced the excel files,I copy part of the out put in the bottom. Please notes that first section of the out put is the test result for Ecel5, second is for Excel2007.
<?php //ShowFormatCode.php
session_start();
$shnum =0;
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');include 'PHPExcel/IOFactory.php';
//echo 'IN pre_load_first20<br>';
$inputFileName = "./upload/TestExcel5.xls";
echo "inputFileName***" .$inputFileName ."***<br>";
display_format($inputFileName,$shnum);
echo "*******************------------------------**************************----------------------------*******************<br>***";
$inputFileName = "./upload/TestExcel2007.xlsx";
echo "inputFileName***" .$inputFileName ."***<br>";
display_format($inputFileName,$shnum);
function display_format($inputFileName,$shnum){ try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
//$objReader = PHPExcel_IOFactory::createReader("Excel5");
$objPHPExcel = $objReader->load($inputFileName);
//$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
if (!$objPHPExcel){
echo 'objPHPExcel is null<br>';
}
else{
echo 'Excel type:***' .$inputFileType .'***<br>';
// echo 'objPHPExcel is NOT null<br>';
;
}
} catch(Exception $e) {
$er = 'Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage();
echo $er;
}
echo 'After try/catch **' .$shnum .'**<br>';
$objPHPExcel->setActiveSheetIndex($shnum);
//echo 'After setActiveSheetIndex**<br>';
$highestColumm = $objPHPExcel->getActiveSheet()->getHighestColumn();
echo 'highestColumm***' .$highestColumm .'***<br>';
$highestRow = $objPHPExcel->getActiveSheet()->getHighestRow();
echo 'highestRow***' .$highestRow .'***<br>';
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumm);
echo 'highestColumnIndex***' .$highestColumnIndex .'***<br>';
$dtcol = array();$nodtcol = array();
$dtdex = array();
$highestRow = 8;
echo 'Only show first 7 rows---------------------<br>';
for($row =2; $row < $highestRow; $row++) {
for ($i = 0; $i < $highestColumnIndex; $i++) {
// echo 'in loop **' .$i .'**column--';
$cell = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($i, $row);
$lt = get_col_letter($i+1);
$range = $lt .$row;
$frmcod = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($i, $row)->getStyle()->getNumberFormat()->getFormatCode();
$v = $cell->getValue();
// echo $range .'*' .$frmnm .'**' .$frmcod .'**value**' .$v .'**<br>';
echo $range .'**' .$frmcod .'**value**' .$v .'**<br>'; //check formatcode
}//for in loop
echo 'End ' .$row .'th row-----------------------------------------------------<br>';
}//for out loop
}//end function display_formatfunction get_col_letter($num){
$comp=0;
$pre='';
$letters=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
//if the number is greater than 26, calculate to get the next letters
if($num > 26){
//divide the number by 26 and get rid of the decimal
$comp=floor($num/26);
//add the letter to the end of the result and return it
if($comp!=0)
// don't subtract 1 if the comparative variable is greater than 0
return get_col_letter($comp).$letters[($num-$comp*26)];
else
return get_col_letter($comp).$letters[($num-$comp*26)-1];
}
else
//return the letter
$num = $num -1;
return $letters[$num];
} ?>
Part of the out put as shown:
inputFileName***./upload/TestExcel5.xls***
Excel type:Excel5
......
End 4th row-----------------------------------------------------
A5GeneralvalueG00000759
B5GeneralvalueF
C5GeneralvalueUMTA
D5GeneralvalueUNNY-03-0344
E5Generalvalue14.08.80
F5Generalvalue3456
G5#,##0.00value61438180.11
H5#,##0.00value61438180.11
I5**"$"#,##0_);[Red]("$"#,##0)value-1234.77**
J5Generalvalue****
K5Generalvalue****
End 5th row-----------------------------------------------------
------------------------*******----------------------------
inputFileName./upload/TestExcel2007.xlsx
Excel type:Excel2007
............
A5GeneralvalueG00000759
B5GeneralvalueF
C5GeneralvalueUMTA
D5GeneralvalueUNNY-03-0344
E5Generalvalue14.08.80
F5Generalvalue3456
G5#,##0.00value61438180.11
H5#,##0.00value61438180.11
I5Generalvalue1234.77
J5Generalvalue****
K5Generalvalue****
End 5th row-----------------------------------------------------