Solved

converting from properties to excel

Posted on 2006-07-24
6
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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:Mayank S
ID: 17173424
You can use open-office for creating XLS files:

http://api.openoffice.org
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

734 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