OpenCSV: How to create CSV file from POJO with custom column headers and custom column positions?

后端 未结 19 1465
温柔的废话
温柔的废话 2020-12-08 04:14

I have created a MappingsBean class where all the columns of the CSV file are specified. Next I parse XML files and create a list of mappingbeans. Then I write that data int

19条回答
  •  不思量自难忘°
    2020-12-08 04:47

    The sebast26's first solution worked for me but for opencsv version 5.2 it requires a little change in the CustomMappingStrategy class:

    class CustomMappingStrategy extends ColumnPositionMappingStrategy {
    private static final String[] HEADER = new String[]{"TradeID", "GWML GUID", "MXML GUID", "GWML File", "MxML File", "MxML Counterparty", "GWML Counterparty"};
    
    @Override
    public String[] generateHeader() {
        super.generateHeader(bean); // without this the file contains ONLY headers
        return HEADER;
    }
    

    }

提交回复
热议问题