Solved

converting from properties to excel

Posted on 2006-07-24
6
214 Views
Last Modified: 2010-03-31
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0
Comment
Question by:royalcyber
6 Comments
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17169810
try using poi api's to access excel:

http://jakarta.apache.org/poi/
0
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 500 total points
ID: 17170008
   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
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17170032
remember you need to download poi library from the above source and keep it in the classpath
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 86

Expert Comment

by:CEHJ
ID: 17170627
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
 
LVL 92

Expert Comment

by:objects
ID: 17171772
you can use the following to create csv

http://ostermiller.org/utils/CSV.html
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 17173424
You can use open-office for creating XLS files:

http://api.openoffice.org
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now