converting from properties to excel

I have a simple java properties file : common_en.properties

key1=joe
key2=newman
key3="<tr><td class="main" colspan="2"> My learnin </td></tr>
...

...

..



I want to write a small java program which will read this and save it as a csv or xls so when I open it

in excel I have key1 in ( col1) and value in ( col2)

can some have any sample code which already does this


Thankyou!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
royalcyberAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Ajay-SinghConnect With a Mentor Commented:
   public void propToExcel(String propFile, String excelFile) throws IOException {
        Properties prop = new Properties();
        InputStream in = new FileInputStream(propFile);
        try {
            prop.load(in);
        }
        finally {
            try {
                in.close();
            }
            catch (IOException ignored) {
            }
        }

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();
        Iterator itr = prop.keySet().iterator();
        int i = 0;
        while (itr.hasNext()) {
            String name = (String) itr.next();
            String value = prop.getProperty(name);
            HSSFRow row = sheet.createRow(i);
            row.createCell((short) 0).setCellValue(name);
            row.createCell((short) 1).setCellValue(value);
            i++;
        }

        OutputStream out = new FileOutputStream(excelFile);
        try {
            workbook.write(out);
        }
        finally {
            try {
                out.close();
            }
            catch (IOException ignored) {
            }
        }
    }
0
 
Ajay-SinghCommented:
try using poi api's to access excel:

http://jakarta.apache.org/poi/
0
 
Ajay-SinghCommented:
remember you need to download poi library from the above source and keep it in the classpath
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
CEHJCommented:
You don't need to use any special library to create a csv file, which you can open in Excel. Of course, a csv file from a properties file can only have one row and is not ordered
0
 
objectsCommented:
you can use the following to create csv

http://ostermiller.org/utils/CSV.html
0
 
Mayank SAssociate Director - Product EngineeringCommented:
You can use open-office for creating XLS files:

http://api.openoffice.org
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.