简体   繁体   中英

What should I do if I need to read excel file with number like =“01” using php reader?

How should I do if I need to read excel file with number like ="01" using php reader?

They don't read data like ="variables" .

Should I use any other excel reader?

I know how to handle it in downloading files like that, using "mso-number-format".

Please, help me out.

require_once '../../lib/reader.php';
$data = new Spreadsheet_Excel_Reader();

$data->setOutputEncoding('utf8');
$data->read('data/'.$_FILES["FILE1"]["name"]);
error_reporting(E_ALL ^ E_NOTICE);


for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {


            for ($j = 1; $j <= $data->sheets[0]['numCols']+1; $j++) {
        $strValue = addslashes(trim(strip_tags($data->sheets[0]['cells'][$i][$j]))); // addslashes , trim, strip_tags

        if ($j ==1) $a = $strValue; // 
        if ($j ==2) $b = $strValue; // 
        if ($j ==3) $c = $strValue; // 
    }

echo $a.$b.$c

If you're reading a number from an Excel worksheet, then it's likely to be held as a simple number ratehr than a string. Either read it and format it using sprintf(), or str_pad(); or check the number format mask of the cell and apply that to your number.

EDIT

It looks like somebody is fudging the workbook to use a formula instead of setting the cell value as a string, or applying a format mask (not particularly sensible).

Looking at the code for Spreadsheet_Excel_Reader (lines 1424-1429) where it handles reading formulae that result in a string value, it doesn't actually set the string value in the cell (which is why you're getting an empty cell value).... this is clearly a bug in the library. Either you'll need to fix this; or switch to an Excel library that can actually read formulae that give a string result value; or fix the original spreadsheet so that it sets the '001' value as a string or a format masked number rather than as a formula.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM