• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

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!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0
royalcyber
Asked:
royalcyber
1 Solution
 
Ajay-SinghCommented:
try using poi api's to access excel:

http://jakarta.apache.org/poi/
0
 
Ajay-SinghCommented:
   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:
remember you need to download poi library from the above source and keep it in the classpath
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now