0

I have a CSV template file, say, having 10 columns. I would like to load this CSV file template, and then write data to the relevant cells(say only to 5 of the 10 cells) through a java program. I went through JSAPAR, SuperCSV etc, but am not sure whether these libraries have the "stuff" what exactly I need. Is there any framework supporting this kind of operations?

user504342
  • 945
  • 2
  • 16
  • 36
active_coder
  • 79
  • 1
  • 2
  • 13
  • Can you see if apache velocity template is helpful for you. Plese see the link- http://gognamunish.blogspot.in/2013/08/apache-velocity-template-to-generate.html – Manu Jun 24 '15 at 10:07
  • This is not work for any csv library. Use some lib to load your template into 2dim array, write your cells and save the array back using same lib. – Pavel Niedoba Nov 19 '19 at 13:41

2 Answers2

0

OpenCSV is generally considered the best CSV toolkit for Java. It's a very lightweight library that makes working with CSV dead simple. I would recommend looking at it since it's not among the list of things you've tried yet.

user504342
  • 945
  • 2
  • 16
  • 36
Mike Thomsen
  • 36,828
  • 10
  • 60
  • 83
  • Thanks for the swift response. I cross checked the OpenCSV framework and it looks good, but doesnt satisfy the "stuff" that I want to accomplish. None of these frameworks, handles loading csv files as templates(similar to loading excel template file and writing to it(Apache POI)). I was wondering is it because CSV is treated as a simple delimiter separated "text" stored in a single file. I have no clues so far on how I can load the csv file as a template and then write to it..Seems it not possible.. :-( – active_coder Jun 30 '14 at 12:11
0

Checkout freemarker: http://freemarker.org/

Open your text file. Enter freemarker paramerters for required cells.

Your template file may look something like below:

"Templatetext1","text2","text4", "${myVal4}",${myVal5}","text6", ${myVal7}",${myVal8}",${myVal9}","textInCell10"

Pass in the values, you have your csv from template.

If you want to pass for multiple rows you can use other elements like <#list> etc.

Espresso
  • 5,378
  • 4
  • 35
  • 66