Skip to main content

Posts

Showing posts from September, 2016

How to convert a CSV file to XLSX

I wrote this utility for a friend of mine who wanted to convert large (~50MB) CSV files to XLSX. The CSV files had comma "," as a delimiter. I have used apache poi utility in this program. https://www.apache.org/dyn/closer.lua/poi/release/RELEASE-NOTES.txt This code uses SXSSFWorkbook class. The SXSSFWorkbook class uses "BigGridDemo" strategy, where only portions being processed are kept in memory. There are temporary files created which store the rest of the temporary data. setCompressTempFiles() method allows these temp files to be compressed. The size of these files can get quite large. The data to be converted was UTF-8 encoded data. So, we are using  OutputStreamWriter, where we specify the encoding of the data. If you do not need the encoding, just remove that parameter from the constructor call of OutputStreamWriter. The system where this ran, supported Java 7, so have not used features in java 8, such as try with exceptions. import java.io.*; im