Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail


Java Server Pages


Java Beans



Java Servlets



Java Code Examples

Interview Questions

Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting


Beginner Guide to Linux Server


Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers


Adware & Spyware Remover

Open Source Softwares

Convert CSV to excel File
Expert:koushil Nath
Hi friend,<br /><br /><br /><br />Code to convert csv to xls file.<br /><br />Some points to be remember.<br /><br /><br />1.&quot;test.csv&quot; is the name of the csv file .<br /><br />2.create a folder &quot;excel&quot; in c: drive.<br /><br />3.&quot;xfile.xls&quot; name of the .xls file create in the &quot;excel&quot; folder. <br /> <br /><br />import java.io.DataInputStream;<br />import java.io.FileInputStream;<br />import java.io.IOException;<br />import java.util.StringTokenizer;<br />import java.util.*;<br />import org.apache.poi.hssf.usermodel.*;<br />import org.apache.poi.hssf.util.*;<br />import java.io.*;<br /><br />public class CsvToXls<br />{ <br /> public static void main(String args[]) throws IOException<br /> { <br /> ArrayList arList=null;<br /> ArrayList al=null;<br /> String fName = &quot;test.csv&quot;;<br /> String thisLine; <br /> int count=0; <br /> FileInputStream fis = new FileInputStream(fName);<br /> DataInputStream myInput = new DataInputStream(fis);<br /> int i=0;<br /> arList = new ArrayList();<br /> while ((thisLine = myInput.readLine()) != null)<br /> {<br /> al = new ArrayList();<br /> String strar[] = thisLine.split(&quot;,&quot;);<br /> for(int j=0;j&lt;strar.length;j++)<br /> {<br /> al.add(strar[j]);<br /> }<br /> arList.add(al);<br /> System.out.println();<br /> i++;<br /> } <br /><br /> try<br /> {<br /> HSSFWorkbook hwb = new HSSFWorkbook();<br /> HSSFSheet sheet = hwb.createSheet(&quot;new sheet&quot;);<br /> for(int k=0;k&lt;arList.size();k++)<br /> {<br /> ArrayList ardata = (ArrayList)arList.get(k);<br /> System.out.println(&quot;ardata &quot; + ardata.size());<br /> HSSFRow row = sheet.createRow((short) 0+k);<br /> for(int p=0;p&lt;ardata.size();p++)<br /> {<br /> System.out.print(ardata.get(p));<br /> HSSFCell cell = row.createCell((short) p);<br /> cell.setCellValue(ardata.get(p).toString());<br /> }<br /> System.out.println();<br /> } <br /> FileOutputStream fileOut = new FileOutputStream(&quot;C:\\excel\\xfile.xls&quot;);<br /> hwb.write(fileOut);<br /> fileOut.close();<br /> System.out.println(&quot;Your excel file has been generated&quot;);<br /> } catch ( Exception ex ) {} //main method ends<br /> } <br />}<br /> <br /><br />Thanks<br />
<p>Thank you so much for this excellent code </p>


<p>The code works awesome with 1 issue.I have a column that contains the value as status<em>completed,status</em>success in csv.But the program is considering status<em>completed and status</em>success as separate columns and the excel is a mess.is that something that can be rectified.Thanks for your help again.</p>

More Questions
Post Answers
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials


Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.