使用SuperCSV更改标题值 [英] Using SuperCSV to Change Header Values

查看:119
本文介绍了使用SuperCSV更改标题值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与这篇有关 SuperCSV的功能的帖子保持一致,SuperCSV可以处理更改标题的值的情况( 仅列名 )是从数据库中读取的?

In line with this post about abilities of SuperCSV, can SuperCSV handle changing the values of the headers(column names only) read from the database?

例如,以下代码段详细说明了当前状态和预期状态.

For example, the following code snippet details the Current State and the Expected State.

输入:

final String[] header = new String[] { "firstName", "lastName", "birthDate"};

// write the header
beanWriter.writeHeader(header);

// write the beans
for( final CustomerBean customer : customers ) {
   beanWriter.write(customer, header, processors);
}

输出:具有列名的文件:

firstName, lastName, birthDate
Bob      , Doe     , 02/12/2013  

预期状态

输入:

final String[] header = new String[] { "firstName", "lastName", "birthDate"};

// write the header
beanWriter.writeHeader(header);

// write the beans
for( final CustomerBean customer : customers ) {
   beanWriter.write(customer, header, processors);
}

// modify the headers
 ??????

输出:具有修改的列名的文件:

First Name, Last Name, Birthday
Bob      , Doe     , 02/12/2013 

非常感谢您的协助.

推荐答案

我不确定这是否能回答您的问题,但是您可以在标题中添加任意内容-它不必与映射相同数组传递给beanWriter.write()

I'm not sure if this answers your question, but you can put whatever you like in the header - it doesn't have to be identical to the mapping array passed to beanWriter.write()

例如,以下内容将提供您想要的输出:

For example, the following will give the output you desire:

final String[] header = new String[] { "First Name", "Last Name", "Birthday"};
final String[] fieldMapping = new String[] { "firstName", "lastName", "birthDate"};

// write the header
beanWriter.writeHeader(header);

// write the beans
for( final CustomerBean customer : customers ) {
   beanWriter.write(customer, fieldMapping , processors);
}

这篇关于使用SuperCSV更改标题值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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