Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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
Magento:通过php excel阅读器,读取excel文件_Excel_Magento - Fatal编程技术网

Magento:通过php excel阅读器,读取excel文件

Magento:通过php excel阅读器,读取excel文件,excel,magento,Excel,Magento,我是magento新手,使用1.7.2。您能告诉我如何在magento中集成PHP excel阅读器,以便系统能够读取excel文件吗 请帮帮我。 提前感谢。Magento通常具有读取.CSV格式文件的功能。 如果您需要集成excel reader,那么您可以通过创建自己的自定义模块来实现。但是.CSV也是一个很好的选择 如果您想在magento中读取csv文件,可以这样做 if(isset($_FILES['file_uplod']['name']) && ($_FILES['

我是magento新手,使用1.7.2。您能告诉我如何在magento中集成PHP excel阅读器,以便系统能够读取excel文件吗

请帮帮我。
提前感谢。

Magento通常具有读取.CSV格式文件的功能。
如果您需要集成excel reader,那么您可以通过创建自己的自定义模块来实现。但是.CSV也是一个很好的选择

如果您想在magento中读取csv文件,可以这样做

if(isset($_FILES['file_uplod']['name']) && ($_FILES['file_uplod']['name'] != ''))
     {

        $filename = $_FILES['file_uplod']['name'];
    $ext = pathinfo($filename, PATHINFO_EXTENSION);

      $uploader = new Varien_File_Uploader('file_uplod');
      $uploader->setAllowedExtensions(array('text/csv',
    'csv','excel','vnd.ms-excel',
    'application/csv',
    'text/comma-separated-values',
    'application/excel',
    'application/vnd.ms-excel',
    'application/vnd.msexcel',
    'text/anytext',
    'application/octet-stream',
    'application/txt')); 
       $uploader->setAllowCreateFolders(true); //for creating the directory if not exists
        $uploader->setAllowRenameFiles(false); //if true, uploaded file's name will be changed, if file with the same name already exists directory.
        $uploader->setFilesDispersion(false);       
      $path = Mage::getBaseDir('media') . DS ;    

      $path = $path ."csv-folder";

      $uploader->save($path, $_FILES['file_uplod']['name']);

      $file = $path."/".$_FILES['file_uplod']['name'];
      $uploader->save($path, $_FILES['file_uplod']['name']);

      $file = $path."/".$_FILES['file_uplod']['name'];
      $csv = new Varien_File_Csv();
      $data = $csv->getData($file);
    //first line are the headers
    $headers = $data[0];
    $allProductData = array();
    for($i=1; $i<count($data); $i++){
      $productData = array();
      foreach ($headers as $index=>$attributeCode) {
          $productData[$attributeCode] = $data[$i][$index];
      }
      $allProductData[] = $productData;
  }
if(isset($\u FILES['file\u uplod']['name'])和($\u FILES['file\u uplod']['name']!='')
{
$filename=$\u文件['file\u uplod']['name'];
$ext=pathinfo($filename,pathinfo_扩展名);
$uploader=新的Varien_文件上传器(“文件上传”);
$uploader->setAllowedExtensions(数组('text/csv'),
“csv”、“excel”、“vnd.ms excel”,
“应用程序/csv”,
“文本/逗号分隔值”,
“应用程序/excel”,
“应用程序/vnd.ms excel”,
'应用程序/vnd.msexcel',
“text/anytext”,
“应用程序/八位字节流”,
‘application/txt’);
$uploader->setAllowCreateFolders(true);//用于创建不存在的目录
$uploader->SetAllowerNameFiles(false);//如果为true,则上载文件的名称将被更改,前提是同名文件已存在于目录中。
$uploader->setfiles(false);
$path=Mage::getBaseDir('media').DS;
$path=$path.“csv文件夹”;
$uploader->save($path,$\u FILES['file\u uplod']['name']);
$file=$path.“/”$\u文件['file\u uplod']['name'];
$uploader->save($path,$\u FILES['file\u uplod']['name']);
$file=$path.“/”$\u文件['file\u uplod']['name'];
$csv=新的Varien_文件_csv();
$data=$csv->getData($file);
//第一行是标题
$headers=$data[0];
$allProductData=array();
对于($i=1;$i$attributeCode){
$productData[$attributeCode]=$data[$i][$index];
}
$allProductData[]=$productData;
}

在此处打印
$allProductData
数组以获取csv中的所有数据。希望这对任何人都有帮助。

如果您想在magento中读取excel文件。您需要开放源代码项目“”

示例代码如下

$path = Mage::getBaseDir('media') . DS;

    $path_to_XML = $path . "csv-folder" . DS . "magento.xls";
    $include_path = dirname(__FILE__);
    $path_to_PHP_ExcelReader = $include_path . "/Excel/reader.php";

    require_once $path_to_PHP_ExcelReader;

    // ExcelFile($filename, $encoding);
    $data = new Spreadsheet_Excel_Reader();

    // Set output Encoding.
    $data->setOutputEncoding('utf-8');
    /* if you want you can change 'iconv' to mb_convert_encoding: */

    $data->setUTFEncoder('mb');

    /*
     * By default rows & cols indeces start with 1
     * For change initial index use:
     */
    $index = 0;

    $data->setRowColOffset($index);
    /* setDefaultFormat - set format for columns with unknown formatting */

    $data->setDefaultFormat('%.2f');

    /* setColumnFormat - set format for column (apply only to number fields) */
    $data->setColumnFormat(4, '%.3f');
    /* Do the actual reading of file */

    $data->read($path_to_XML);
    echo "<pre>";


    print_r($data);
    exit;
$path=Mage::getBaseDir('media')。DS;
$path_to_XML=$path。“csv文件夹”。DS。“magento.xls”;
$include\u path=dirname(\u文件\u);
$path_to_PHP_ExcelReader=$include_path。“/Excel/reader.php”;
需要_once$path_to_PHP_ExcelReader;
//ExcelFile($filename,$encoding);
$data=新的电子表格\u Excel\u阅读器();
//设置输出编码。
$data->setOutputEncoding('utf-8');
/*如果需要,可以将“iconv”更改为mb\u convert\u编码:*/
$data->setUTFEncoder('mb');
/*
*默认情况下,行和列索引以1开头
*更改初始索引使用:
*/
$index=0;
$data->setRowColOffset($index);
/*setDefaultFormat-为格式未知的列设置格式*/
$data->setDefaultFormat('%.2f');
/*setColumnFormat-设置列的格式(仅适用于数字字段)*/
$data->setColumnFormat(4,%.3f');
/*进行文件的实际读取*/
$data->read($path\u to\u XML);
回声“;
打印(数据);
出口

您所需要做的就是解压缩到包含需要XLS支持的类的同一目录中

这个问题对于您为什么要读取excel文件来说非常模糊。您可以直接在Magento中导入/导出csv文件,或使用Magmi导入包含产品的csv文件。