第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從一個讀取并寫入第二個excel文件 - PHP

從一個讀取并寫入第二個excel文件 - PHP

PHP
SMILET 2022-07-09 16:32:15
我有一個包含大量數(shù)據(jù)的 excel 文件,這是在編輯器中打開一行的示例:"A","001270","3755","TRIPP LITE MASTER-POWER","UPS EXTERNAL BATTERY PACK TOWER","12/24V APS INVERTER CHARGERS","0000000000000421.20","BP-260","000019.80","0037332080011","0015.00","0014.00","0019.50","","0000000000000222.80","0000000000000000.00","N","","UPS-C","BATT","0101","","N","","00000000000000.0000","2 YEAR LTD",""我有這段代碼在一種情況下效果很好$table = fopen('read.csv','r');$temp_table = fopen('write','w');while (($data = fgetcsv($table)) !== FALSE){    if(in_array($data[1],$spec)){ // this is if you need the first column in a row        continue;    }    fputcsv($temp_table,$data);}fclose($table);fclose($temp_table);結(jié)果在新文件中我得到了這樣的行:A,001270,3755,"TRIPP LITE MASTER-POWER","UPS EXTERNAL BATTERY PACK TOWER","12/24V APS INVERTER CHARGERS",0000000000000421.20,BP-260,000019.80,0037332080011,0015.00,0014.00,0019.50,,0000000000000222.80,0000000000000000.00,N,,UPS-C,BATT,0101,,N,,00000000000000.0000,"2 YEAR LTD",問題是當我在編輯器中打開一個新文件時,它在值的開頭和結(jié)尾都沒有“”,這就是問題所在,我做錯了什么?
查看完整描述

1 回答

?
慕碼人8056858

TA貢獻1803條經(jīng)驗 獲得超6個贊

您的代碼看起來不錯,您只需要放在.csvline 上$temp_table = fopen('write.csv','w');,因為您fputcsv()在 while 循環(huán)中使用函數(shù)。它基于 csv 文件標準生成輸出。如果您以.txt格式獲得輸出,則某些列會缺少引號""。在這種情況下,您需要手動處理。


編輯


如果您不想將其輸出為 csv 而不是用以下更新的代碼替換您的代碼。


$table = fopen('read.csv','r');

$temp_table = fopen('write.txt','w');

while (($data = fgetcsv($table)) !== FALSE){

    $data = '"'. implode('","', $data) .'"'; // this line will add the comma and double quote to each array value and wrap the string with double quote.

    fputs($temp_table,$data);

}

fclose($table);

fclose($temp_table);


查看完整回答
反對 回復(fù) 2022-07-09
  • 1 回答
  • 0 關(guān)注
  • 92 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號