Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHPExcel读取MS Excel文件,并转换数据以构建一些senteces_Php_Phpexcel_Php 5.3 - Fatal编程技术网

使用PHPExcel读取MS Excel文件,并转换数据以构建一些senteces

使用PHPExcel读取MS Excel文件,并转换数据以构建一些senteces,php,phpexcel,php-5.3,Php,Phpexcel,Php 5.3,我不明白,我需要一些帮助。我正在使用PHPExcel读取XLS文件,如下所示: include 'Classes/PHPExcel/IOFactory.php'; $inputFileName = 'precios.xls'; // Read your Excel workbook try { $inputFileType = PHPExcel_IOFactory::identify($inputFileName); $objReader = PHPExcel_IOFact

我不明白,我需要一些帮助。我正在使用PHPExcel读取XLS文件,如下所示:

include 'Classes/PHPExcel/IOFactory.php';

$inputFileName = 'precios.xls';

//  Read your Excel workbook
try {
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($inputFileName);
} catch (Exception $e) {
    die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
}

$rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
$array_data = array();
foreach ($rowIterator as $row) {
    $cellIterator = $row->getCellIterator();
    $cellIterator->setIterateOnlyExistingCells(false);
    $rowIndex = $row->getRowIndex();
    $array_data[$rowIndex] = array('A' => '', 'B' => '', 'C' => '', 'D' => '', 'E' => '', 'F' => '', 'G' => '');

    foreach ($cellIterator as $cell) {
        if ('A' == $cell->getColumn()) {
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        } else if ('B' == $cell->getColumn()) {
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        } else if ('C' == $cell->getColumn()) {
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        } else if ('D' == $cell->getColumn()) {
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        } else if ('E' == $cell->getColumn()) {
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        } else if ('F' == $cell->getColumn()) {
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        } else if ('G' == $cell->getColumn()) {
            $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();
        }
    }
}

echo '<pre>';

print_r($array_data);
我需要做的是,从这里开始,但我不知道如何将结果转化为:

foreach ($cellIterator as $cell) {
    $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();        
}

另外请注意数字“.”对于值,是否可以给我一些想法或一些示例代码来完成此操作?

首先要做的事情。在if/else代码块中,所有语句都是相同的。如果您不打算在每种情况下做任何不同的事情,那么您应该将代码更改为

$str = "";
for ($i = 0; $i < count($arr); $i++) {
    if ($i > 1) {
        $str .= ($i-1)*6;
    } else {
        $str .= $i;
    }
    $str .=  .":". substr($arr, 0, 2) . "." . substr($arr, 3);
}
至于你的问题,我将使用for计数器遍历数组

$str=”“;
对于($i=0;$i1){
$str.=($i-1)*6;
}否则{
$str.=$i;
}
$str.=.“:”.substr($arr,0,2)。“.substr($arr,3);
}
foreach ($cellIterator as $cell) {
    $array_data[$rowIndex][$cell->getColumn()] = $cell->getCalculatedValue();        
}
$str = "";
for ($i = 0; $i < count($arr); $i++) {
    if ($i > 1) {
        $str .= ($i-1)*6;
    } else {
        $str .= $i;
    }
    $str .=  .":". substr($arr, 0, 2) . "." . substr($arr, 3);
}