Solved

converting from properties to excel

Posted on 2006-07-24
6
252 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

688 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