簡體   English   中英

在php中將文件創建為Excel格式時,如何擺脫Excel可笑的自動格式

[英]How do I get rid of excels ridiculous auto format when creating a file in php to excel format

我有一個程序使該文件成為excel文件,並且我擁有它,因此它擺脫了啞格式mc excel,但不會擺脫########

這種格式發生在mc excel中,似乎單元格中有符號-。 但並非所有人都這樣。

清理代碼是:

function cleanData(&$str)
  {
   // escape tab characters
    $str = preg_replace("/\t/", "\\t", $str);

    // escape new lines
    $str = preg_replace("/\r?\n/", "\\n", $str);

    // convert 't' and 'f' to boolean values
    if($str == 't') $str = 'TRUE';
    if($str == 'f') $str = 'FALSE';

    // force certain number/date formats to be imported as strings
    if(preg_match("/^0/", $str) || preg_match("/^\+?\d{8,}$/", $str) || preg_match("/^\d{4}.\d{1,2}.\d{1,2}/", $str)) {
      $str = "'$str";
    }

    // escape fields that include double quotes
    if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';

  }

需要幫助請叫我!

謝謝。

當單元格的內容對於默認的列大小而言太大時,MS Excel將顯示“ #########”:與文本中的符號無關。 單元格中的值仍然正確,但是使用制表符分隔的值文件時無法設置列寬,因此,除非切換到真實的Excel文件,否則無法對此進行控制。

如果必須使用制表符分隔的值文件; 為什么不使用PHP內置的fputcsv()函數,而不是編寫自己的制表符分隔值轉換?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM