views:

772

answers:

4

Hi All,

I need to convert a semi-colon delimited file to an Excel. However, there are some fields that must be removed from the Excel file, and some extra fields to be added. These extra fields are drop-down fields.

Is there any way to do this? Programming language that is preferably to be used is Java, but also welcome the possibility to use excel macro.

Thanks

A: 

You could look at opencsv and HSSF.

Matthew Flaschen
Does this two can add new fields/columns and allow those columns to be a drop down?Thanks
You can definitely define additional columns (beyond the CSV) if you do it this way. However, I'm not sure what you mean by "drop-down" here.
Matthew Flaschen
+2  A: 

I'm pretty sure you can do this with vanilla Excel. You can either do a global search and replace on semicolon to comma and just open as CSV or use the "Text to Columns" feature.

EDIT: I've not done this programmatically in Java, but in Perl it should be pretty straightforward with Text::xSV and Spreadsheet::WriteExcel

jiggy
Hi Jiggy,I can't use global search and replace as there are already some commas in the file. As for Text To Columns, it does work, however, I'm trying to do it with the least human work as possible.You can't remove fields and add fields manually with Text To Columns.Thanks.
A: 

I'm not sure how to do this with an Excel macro, but for Java:

  1. Read the file with FileReader
  2. Use a StringTokenizer with a ";" delimeter to separate the fields
  3. Make an array for each row holding a custom object representing each row. The object can store arrays for the data needed to populate the drop down box
  4. Use Apache POI to create an Excel spreadsheet (There are lots of POI examples on Stackoverflow)
ewh105
A: 

You have two options:

  1. Use Apache POI to write and customise the XLS
  2. Create a sample spreadsheet in Excel, but save it as an HTML page. Take the saved HTML and use it as a template for your data. You can save the output (template+data) as a file with .xls suffix. Even though its content is really HTML it will open correctly.

If you use CSV you won't be able to get additional features such as drop downs or styling.

David Rabinowitz