3

I want to read data form an Excel file and show in html. I know there are several libraries like PHPExcel, PHP-ExelReader that do so.

But, I also want to keep the format that was in excel file.
For example :

−19×10−17 J should be parsed as −19&times;10<sup>−17</sup> J And
m1r1 : m2r2 as m<sub>1</sub>r<sub>1</sub> : m<sub>2</sub>r<sub>2</sub>.

Is there any library that could do so? I have googled but did not get any solution for this. Please recommend some libraries or any tutorial for this task.

Any help will be highly appreciated.

Update - I also want to store data in database.

4

1 に答える 1

2

解決策を得ました。PHPエクセルです。

セルから値をフェッチしている間、私がしたことは次のとおりです。

$value = $cell->getValue();
if($value instanceof PHPExcel_RichText)
{
    $cellValueAsString = '';
    $elements = $value->getRichTextElements();
    foreach ($elements as $element)
    {
        if ($element instanceof PHPExcel_RichText_Run) 
        {
            if ($element->getFont()->getSuperScript()) 
            {
                $cellValueAsString .= '<sup>';
            } 
            else if ($element->getFont()->getSubScript()) 
            {
                $cellValueAsString .= '<sub>';
            }
        }

        $cellText = $element->getText();
        $cellValueAsString .= htmlspecialchars($cellText);
        if ($element instanceof PHPExcel_RichText_Run) 
        {
            if ($element->getFont()->getSuperScript()) 
            {
                $cellValueAsString .= '</sup>';
            } 
            else if ($element->getFont()->getSubScript()) 
            {
                $cellValueAsString .= '</sub>';
            }
        }
    }

    $value = $cellValueAsString;
}
于 2013-05-04T09:11:59.233 に答える