doushi9780 2017-11-06 11:24
浏览 38

Excel将1/1转换为日期(DD.MM.YYYY)

I am exporting a CSV from web app and I have a column Format which can be for example 1/1 or 1/6... and Excel converts it as 1.1.2017. or 1.6.2017.

This is my function for export:

public function exportCSVPrint($id)
    {
        $tablePrint = DB::connection('mysql2')->table('mc_schaltdaten_print')->select('s_magazin', 'datum', 's_ausgabe', 's_ausrichtung', 's_jahrgang', 's_format', 's_seite', 's_seiten', 'brutto', 'pzn')->where('spotid', $id)->get();
        $csv        = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());

        $header = [Lang::get('language.magazine'), Lang::get('language.date'), Lang::get('language.ausgabeVersion'), Lang::get('language.seite'), Lang::get('language.seiten'), 'Format', Lang::get('language.ausrichtung'), Lang::get('language.anzeigenPreis')];
        $csv->setDelimiter(';');
        $csv->insertOne($header);

        foreach ($tablePrint as $t) {
            $rows = [
                [$t->s_magazin, $t->datum, $t->s_ausgabe, $t->s_seite, $t->s_seiten, $t->s_format, $t->s_ausrichtung, $t->brutto],
            ];

            $csv->insertAll($rows);
        }
        $csv->output($id . '.csv');
    }

How can I get it as original 1/1, not date format?

  • 写回答

1条回答 默认 最新

  • duancenxie2233 2017-11-06 11:26
    关注

    Annoying isn't it?

    Excel "helpfully" assumes that you've typed a date, with the year appropriately defaulted, when you type something like a / b.

    You can retain the original text if you prefix the string with the single quotation character '.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入