CSVPrinter 数据显示未在列中分隔 [英] CSVPrinter datas appears not separated in columns

查看:26
本文介绍了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

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

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天全站免登陆