Tuesday, July 2

Converting CSV File in to Excel File Using JAVA

Hi ALL,

Here I write a program for Convert the CSV file to MS Excel file using JAVA.


/*Import  file declaration*/

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.*;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import java.io.*;

public class csvTOexcel {

    public static void main(String args[]) throws IOException {
        ArrayList arrayList = null;
        ArrayList al = null;

        String FileName = "C:\\Documents and Settings\\SKitech\\Desktop\\bala\\auto_reg.csv"; //Source file name & path
        String CLine;
        int count = 0;

        FileInputStream fis = new FileInputStream(FileName);
        DataInputStream dis = new DataInputStream(fis);
        int i = 0;
        arrayList = new ArrayList();
        while ((CLine = dis.readLine()) != null) {
            al = new ArrayList();
            String strar[] = CLine.split(",");
            for (int j = 0; j < strar.length; j++) {
                al.add(strar[j]);
            }
            arrayList.add(al);
            System.out.println(al); // Write a values in console
            i++;
        }

        try {
            HSSFWorkbook hwb = new HSSFWorkbook();
            HSSFSheet sheet = hwb.createSheet("My Sheet");
            for (int k = 0; k < arrayList.size(); k++) {
                ArrayList ardata = (ArrayList) arrayList.get(k);
//System.out.println("ardata " + ardata.size());
                HSSFRow row = sheet.createRow((short) 0 + k);
                for (int p = 0; p < ardata.size(); p++) {
//System.out.print(ardata.get(p));
                    HSSFCell cell = row.createCell((short) p);
                    cell.setCellValue(ardata.get(p).toString());
                }
                System.out.println();
            }
            FileOutputStream fileOut = new FileOutputStream("C:\\xls\\auto_reg1.xls");
            hwb.write(fileOut);
            fileOut.close();
            System.out.println("Your excel file has been generated");
        } catch (Exception ex) {
        } //main method ends
    }
}

OUTPUT:

~~~~~~~~~


[00079584, 00052705, The Five C's of Writing in Today's Business Environment, AYDINBE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BASAREV1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BEEREBA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BEIJEED1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BENTRO1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BEZEMRI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BLOKHAR1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BOESSNA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BOLRO1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BOMHOVA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BONNIPA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BOSCHPE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BOUKHSA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BRANDKA4]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BRESHA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BRUENFR1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BRUGTHI2]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, BUITEAP1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, CLAASRE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, DAALMDA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, DAAMEIN1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, DACHAHE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, DEBETPE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, DEKKECA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, DIJKHHA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, DUNNIFL1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, EDELSEL1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, EIMERFR1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, ENGERSA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, ENTINHA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, ERMERAN1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, FAOUZJA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, FRANKST5]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, FREEHA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, GILSAD1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, GRAAFHA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, GRAAFMA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, GRAAFSI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, GRAATKA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, GREFTWI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, HAANDA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, HALIESA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, HARTOBR1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, HAVELWE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, HEERDLI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, HILTECA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, HOGARAL1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, HORDIAA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, HULTEDE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, IJZERCA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, IMHOFLI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, JANSSRO1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, JURAWRA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, KEMPEAN3]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, KETELMA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, KLAWEIN1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, KLEINAN4]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, KUENEEL1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, KUNSTVI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, LATERSU1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, LEMOUMO1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, LIEASMO1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, LIERELO1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, LOHBEMI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, LOOHUEL1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, MARIVI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, MOKHTAH1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, NEUMAPA2]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, NIEUWKA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, NOBELSU2]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, PENNIHA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, PERUMDE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, PLUIMWI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, RAADDE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, RAADPI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, RAVELLE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, RENETNA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, RIETVJO1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, ROOYLI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, ROSBE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, RUISBNI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, SCHONJA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, SCHRADA3]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, SILVEJU1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, STOLTLE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, SWINKRA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, TAHAPSU2]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, THOBEED1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, VALKCH1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, VANDEEV3]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, VERHORE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, VERKOCA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, VRIESGI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, VRIESMA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, WESTEPI1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, WILKSA1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, WILTEFE1]
[00079584, 00052705, The Five C's of Writing in Today's Business Environment, WITLOME1]



this Data write in Excel File.


Your excel file has been generated

No comments:

Post a Comment

Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...