CSVPrinter数据似乎没有按列分开 [英] CSVPrinter datas appears not separated in columns

查看:45
本文介绍了CSVPrinter数据似乎没有按列分开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此库 commons-csv(1.5)生成csv文件,我已经编写了一个简单的程序来查看结果:

I'm trying to use this library commons-csv (1.5) for generating the csv file, i've make a simple program for seeing the result :

String SAMPLE_CSV_FILE = "./sample.csv";

        try (
            BufferedWriter writer = Files.newBufferedWriter(Paths.get(SAMPLE_CSV_FILE));
            CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.EXCEL
                    .withHeader("ID", "Name", "Designation", "Company"));
        ) {
            csvPrinter.printRecord("1", "Name1 ", "CEO", "Google");
            csvPrinter.printRecord("2", "Name2", "CEO", "Microsoft");

            csvPrinter.flush();            
        }

我的CSV格式很好,但是标题和数据并没有在每一列中分开,当我打开CSV文件时,我在第一列中看到了所有数据和标题

My CSV is well generated but the header and the data isnt separated in each column, When I open the CSV file, I see all the data and header in the first column

我还没有找到好的CSVFormat,如何将它们分开?

I dont found yet the good CSVFormat, how to separate them ?

推荐答案

在运行您的程序时,按预期,我得到的所有列均以逗号分隔.如果您使用Excel打开文件,请确保已选择逗号作为定界符而不是制表符.

When I run your program, I get all the columns separated by comma's as expected. If you're using Excel to open the file, make sure you have selected the comma as the delimiter instead of the tab.

这篇关于CSVPrinter数据似乎没有按列分开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆