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 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 matlab有关常微分方程的问题求解决
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法