douyu3145 2014-06-26 08:55
浏览 70

在PHP中将空格添加到CSV编号

I have a system that takes an Excel file, does some manipulation and then exports to a CSV file ready for import into something else.

Everything works except the numbers; when the CSV file is import into the final system the numbers show up as 1E+11 for example.

I have a previous CSV file that works and the only difference I can see when I open it in Notepad is that there is a whitespace after the number e.g

123456643567 ,872871643567 ,465435654356 

Whereas the new file doesn't have any whitespace after the number e.g

123456643567,872871643567,465435654356

This is the only difference I can see so can only presume this is causing the problem, however I don't know how to add that white space in. If I try and just append a whitespace to the end then the numbers are surrounded by speech marks and this still doesn't work e.g

"123456643567 ","872871643567 ","465435654356 "

Is there a way to add this in or is there something else at work causing this issue?

Edit:

For reference, below is the code I have to read in the Excel file using PHPExcel:

// Identify the type of $file
$file_type = PHPExcel_IOFactory::identify($file);
// Create a new Reader of the type that has been identified
$reader = PHPExcel_IOFactory::createReader($file_type);
// Load $file to a PHPExcel Object
$obj = $reader->load($file);
// Load file into rowIterator
$rows = $obj->getActiveSheet()->getRowIterator();
// Create array
$excel_array = array();
foreach($rows as $row){
    $cells = $row->getCellIterator();
    $index = $row->getRowIndex ();
    // Check row contains data
    if($index>=$req_array[$req][0]){
        foreach ($cells as $cell) {
            $column = $cell->getColumn();
            // Check column is needed
            if(strpos($req_array[$req][1],'|'.$column.'|')!==false){
                $excel_array[$index][$column] = $cell->getCalculatedValue();
            }
        }
    }
}
// Return array
return $excel_array;

The req_array just includes a string of required columns and the row to start on.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 孟德尔随机化结果不一致
    • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法