title: OpenCSV: How to create CSV file from POJO with custom column headers and custom column positions?
body: <p>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 into CSV file as report.</p>
  
  <p>I am using following annotations:</p>
  
  <pre><code>public class MappingsBean {
  
      @CsvBindByName(column = "TradeID")
      @CsvBindByPosition(position = 0)
      private String tradeId;
  
      @CsvBindByName(column = "GWML GUID", required = true)
      @CsvBindByPosition(position = 1)
      private String gwmlGUID;
  
      @CsvBindByName(column = "MXML GUID", required = true)
      @CsvBindByPosition(position = 2)
      private String mxmlGUID;
  
      @CsvBindByName(column = "GWML File")
      @CsvBindByPosition(position = 3)
      private String gwmlFile;
  
      @CsvBindByName(column = "MxML File")
      @CsvBindByPosition(position = 4)
      private String mxmlFile;
  
      @CsvBindByName(column = "MxML Counterparty")
      @CsvBindByPosition(position = 5)
      private String mxmlCounterParty;
  
      @CsvBindByName(column = "GWML Counterparty")
      @CsvBindByPosition(position = 6)
      private String gwmlCounterParty;
  }
  </code></pre>
  
  <p>And then I use <code>StatefulBeanToCsv</code> class to write into CSV file:</p>
  
  <pre><code>File reportFile = new File(reportOutputDir + "/" + REPORT_FILENAME);
  Writer writer = new PrintWriter(reportFile);
  StatefulBeanToCsv&lt;MappingsBean&gt; beanToCsv = new 
                                StatefulBeanToCsvBuilder(writer).build();
  beanToCsv.write(makeFinalMappingBeanList());
  writer.close();
  </code></pre>
  
  <p>The problem with this approach is that if I use <code>@CsvBindByPosition(position = 0)</code> to control 
  position then I am not able to generate column names. If I use <code>@CsvBindByName(column = "TradeID")</code> then I am not able to set position of the columns.</p>
  
  <p>Is there a way where I can use both annotations, so that I can create CSV files with column headers and also control column position? </p>
  
  <p>Regards,
  Vikram Pathania</p>