繁体   English   中英

如何使用apache.commons.csv的CSVPrinter写空白列

[英]how to write a blank column with CSVPrinter of apache.commons.csv

我正在使用CSVPrinter来读写CSV。 在编写CSV时,我想写一个空白列,例如“ x”,“ y”(第二列)。 但不幸的是,它写为“ x”,“”,“ y”。 如何使用CSVPrinter写空白列? 我用下面的东西写它。 甚至,我在CSVPrinter文档中也找不到它。 请帮我。

printer.print(null)->“” printer.print(“”)->“”

谢谢

您要查找的行为仅在1.5版中添加:

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-csv</artifactId>
        <version>1.5</version>
    </dependency>

使用此API,您可以应用ALL_NON_NULL引用模式:

    CSVFormat customFormat = CSVFormat.DEFAULT
            .withQuoteMode(QuoteMode.ALL_NON_NULL);

    CSVPrinter printer = new CSVPrinter(System.out, customFormat);
    printer.print("x");
    printer.print("");
    printer.print(null);
    printer.print("y");
    printer.println();

输出:

"x","",,"y"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM