Create XLS java

Create XLS java

If you are trying to create XLS sheet using java without using any third party API. You could use PrintWriter class which prints formatted representations of objects to text output stream. Please have java program below:

package com.javahonk.xls;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class CreateXLS {

    PrintWriter pw;

    public CreateXLS(PrintWriter pw) {
        this.pw = pw;

    }

    public void close() {
        if (pw != null) {
            pw.close();
            pw = null;
        }
    }

    public static void main(String[] args) {

        PrintWriter lPw;
        CreateXLS createXLS = null;

        try {

        lPw = new PrintWriter(
                new FileWriter("C:/Workspace/CreateXLS.xls"));
        createXLS = new CreateXLS(lPw);
        lPw.print("First Name\t");
        lPw.print("Last Name\t");
        lPw.println();
        for (int i = 0; i < 5; i++) {
            lPw.print("Java\t");
            lPw.print("Honk\t");
            lPw.println();
        }

        } catch (IOException iOException) {
            iOException.printStackTrace();
        } finally {
            createXLS.close();
        }
    }
}

 

XLS sheet screen shot:

Create XLS java

Leave a Reply

Your email address will not be published. Required fields are marked *