[英]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? 如果我需要使用php reader读取数字为=“ 01”的Excel文件怎么办?
They don't read data like ="variables" . 他们不读取像=“ variables”这样的数据。
Should I use any other excel reader? 我应该使用其他的excel阅读器吗?
I know how to handle it in downloading files like that, using "mso-number-format". 我知道如何使用“ 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. 如果您正在从Excel工作表中读取数字,则该数字很可能以简单数字的形式保存而不是字符串。 Either read it and format it using sprintf(), or str_pad();
可以使用sprintf()或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. 看一下Spreadsheet_Excel_Reader的代码(第1424-1429行),该代码在其中处理读取导致字符串值的公式,但实际上并没有在单元格中设置字符串值(这就是为什么要获取空单元格值的原因)。 ...这显然是库中的错误。 Either you'll need to fix this;
您可能需要解决此问题; or switch to an Excel library that can actually read formulae that give a string result value;
或切换到可以实际读取给出字符串结果值的公式的Excel库;或者 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.
或修复原始电子表格,以便将“ 001”值设置为字符串或带掩码格式的数字而不是公式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.