Tag: fgetcsv

检查上传的excel文件中的列数

我正在创build一个网页,您必须上传一个Excel文件(csv,xls或xlsx)。 然后我必须检查文件中的列数,因为can只能包含两列。 我已经find了如何做到这一点,但仅限于csv文件: if (($file = fopen($path, "r")) !== FALSE){ while ($line = fgetcsv($file)){ $numcols = count($line); if ($numcols != 2) { echo "The number of columns in your file is not correct. The file must contain only 2 columns. "; break; } $col = $line[0]; echo "right! numcols = " . $numcols . "<br>"; […]

使用PHP读取Excel csv行被切断

当我读取CSV(用PHPExcel,fgetcsv())我想在我的数据库中导入行被切断。 1 fields in line 1: ProCatId;CatName;CatDescription;CatNameisactive;CatNameiswebactive;ProSubCatId;SubCatName;SubCatDesc;SubcatWebDiscription2;SubcatWebDiscription3;SubcatCatName;SubcatSequencenr;SubCatNameisactive;SubCatNameiswebactive;DisplayMode;ProductId;ProductName;ProductDescription;ProductCatName;ProductSubCatName;Express;NextDayDelivery;Sequencenr;Drukvorm;Afwerking;BreedteDrukwerk;HoogteDrukwerk;Papier;PrinterName;PrinterProductCode;WebDescription;WebDescription2;WebDescription3;DeliveryInfo;NextDayPrice;NextDayTransferPrice;NextDayCostPrice;Meta-Keywords;Meta-Description;URL-Trefwoorden;Titel;Filepath_icons;Format;MaterialType;NoOfPages;PrintFront;PrintBack;BleedTop;BleedBottom;BleedLeft;BleedRight;MINH;MAXH;MINW;MAXW;De 1 fields in line 2: liveryScheduleId;DeliveryScheduleName;CentralProductDetailId;ClaimsId;ClaimsName;DruktechniekenId;DruktechniekenName;Verzameld op;Vast;Variabel;vorm;"prijs 1 fields in line 3: drukken 这些字段应该全部在行1中。当我使用php函数file_get_contents()时,内容看起来是有效的。 在Excel中加载文件也没有问题。 我使用下面的代码(,分开): <?php if (($handle = fopen($inputFileName, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for […]