In PHP, I’m trying to read an Excel file using COM():
$rrc_app = new COM("Excel.application");
$rrc_workbook = $rrc_app->Workbooks->Open($filename);
$rrc_worksheet = $rrc_workbook->Worksheets('Top sheet');
$rrc_worksheet->activate;
I tried to extract the value of a cell containing a “Time” value:
$review_time = $rrc_worksheet->Range("C30")->value;
However, it returns a decimal number:
0.604166666667
I know I can use the Format() function of VB, but I don’t know from what object in PHP to call it from. The following:
$review_time = Format($rrc_worksheet->Range("C30")->value, "hh:mm:ss");
Gives:
Fatal error: Call to undefined function Format() in C:\xampplite\htdocs\pmc\index.php on line 40
Do you happen to know how I can call this Format() function using PHP?
Thanks in advance
Formatis a function of theVBA.Stringmodule, so it’s not part of the Excel COM library and I’m not sure if it is accessible via COM at all.However, you can use the
Textproperty instead ofValue: This returns a formatted string (according to the cell format in Excel) rather than the underlying value:EDIT: If the cell does not have the correct format yet, you can change the format before reading the
Textproperty (untested):