Thursday 5 March 2015

Create XLS File In Java


Here is video tutorial  : Generate XLS In java
 
Step 1:
download poi jar

step 2:
 add jar in  your project

step 3:

import  java.io.*;
import org.apache.poi.*;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class CreateExlFile{
    public static void main(String[]args){
   try{
   String filename="/home/shivam/java/mydb.xls";

   HSSFWorkbook workbook=new HSSFWorkbook();
   HSSFSheet sheet =  workbook.createSheet("FirstSheet"); 
   HSSFRow rowhead=   sheet.createRow((short)0);
   rowhead.createCell((short) 0).setCellValue("No.");
   rowhead.createCell((short) 1).setCellValue("Name");
   rowhead.createCell((short) 2).setCellValue("Address");
   rowhead.createCell((short)3).setCellValue("Email");

   HSSFRow row=   sheet.createRow((short)1);
   row.createCell((short) 0).setCellValue("1");
   row.createCell((short) 1).setCellValue("shivam dhiman");
   row.createCell((short) 2).setCellValue("India");
   row.createCell((short) 3).setCellValue("xyz@gmail.com");

   FileOutputStream fileOut =  new FileOutputStream(filename);
   workbook.write(fileOut);
   fileOut.close();
   System.out.println("Your excel file has been generated!");

   } catch ( Exception ex ) {
       System.out.println(ex);

   }
      }
  }


Visit Video Here : Generate Excel In Java

4 comments:

  1. To learn shorter programs when compared to Java then it is the right time to choose python training. There is increasing market demand for professionals who have completed python training.
    python training in chennai | python training institutes in chennai

    ReplyDelete
  2. Can I append to the end of the spreadsheet frequently at different times. I have not tested this yet. How do I do that?

    ReplyDelete
  3. This process takes place at the same time when the peer downloads this lumps of folders.
    shareit app - the file transferring tool

    ReplyDelete