1 Attachment(s)

Need a java code to read 2-dimensional excel file and write as 1-dimensional file

I have tried vba macro it was working fine and as i am new to java i am unable to write code to convert 2-dimensional excel file and write as 1-dimensional file

here by i attached the sample excel - i need the java code to convert it and also i attached the vba code which i used - please help me to sort it out

Sub format_data()

Dim ws As Worksheet

Dim i As Long, j As Long, lrow As Long, lcol As Long, lastrow As Long

Application.ScreenUpdating = False

Set ws = Worksheets("Sheet2")

ws.Range("A1:I1").Value = Split("Name,Name Code,Family Code,Family name,Location Code,Apartment Location, Apartment Logo, Facility, Cost", ",")

ws.Rows(1).Font.Bold = True

With Worksheets("Sheet1")

lrow = .Range("A" & .Rows.Count).End(xlUp).Row

lcol = .Range("IV1").End(xlToLeft).Column

For j = 5 To lcol

For i = 7 To lrow

If .Cells(i, j).Value = "X" Then

lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row

.Range(.Cells(1, j), .Cells(5, j)).Copy

ws.Range("A" & lastrow + 1).PasteSpecial (xlPasteValues), Transpose:=True

.Range("A" & i & "j" & i).Copy ws.Range("F" & lastrow + 1)

End If

Next i

Next j

End With

ws.Cells.EntireColumn.AutoFit

MsgBox "Done"

Application.ScreenUpdating = True

End Sub

thank you in advance

Re: Need a java code to read 2-dimensional excel file and write as 1-dimensional file

Go and read up on Apache POI. It's a very easy library to read (an write) Excel sheets. Easy API, excellent documentation and lots of examples.

Re: Need a java code to read 2-dimensional excel file and write as 1-dimensional file