i have problems to convert text to calc using macro. I want to convert text file to calc with specific format. I have text file below.
000001/001 25/05/05 1657.88
000002/001 25/05/05 2,4910.63
000012/003 19/04/05 0.10
000016/002 20/04/05 7,5000.00
000016/006 20/04/05 13,5000.00
000021/003 20/04/05 7000.00
000021/004 20/04/05 32,5000.00
Before using Open Office, i use excel macro to convert the text file to xls. And the text file above become like below (on excel).
000001/001 25/05/05 1657.88
000002/001 25/05/05 24,910.63
000012/003 19/04/05 0.10
000016/002 20/04/05 75,000.00
000016/006 20/04/05 135,000.00
000021/003 20/04/05 7000.00
000021/004 20/04/05 325,000.00
On the third column, excel correcting the thousands separator (comma) to the right position (without any additional step). But on Open Office, it don't do anything to correct the thousands separator. This is my macro code using Open Office Basic :
Code: Select all
Sub ImportText()
oFileDialog = CreateUnoService( "com.sun.star.ui.dialogs.FilePicker" )
With oFileDialog
.appendFilter( "Text CSV (*.txt;*.csv;*.xls)", "*.txt" )
.appendFilter( "Text (*.txt)", "*.txt" )
.appendFilter( "Text Encoded (*.txt)", "*.fixcc" )
.appendFilter( "Text File (Fixed Width)", "*.fixcc" )
.Title = "Select File"
.setDisplayDirectory( ConvertToURL( "C:\") )
End With
If oFileDialog.execute() = com.sun.star.ui.dialogs.ExecutableDialogResults.OK then
sUrl = oFileDialog.Files(0)
Dim FileProperties(1) As New com.sun.star.beans.PropertyValue
FileProperties(0).Name = "FilterName"
FileProperties(0).Value ="Text - txt - csv (StarCalc)"
FileProperties(1).Name = "FilterOptions"
FileProperties(1).Value = "FIX,,0,1,0/2/10/36/19/4"
oCSV = StarDesktop.loadComponentFromURL( sUrl, "_blank", 0, FileProperties())
oSourceSheet = oCSV.Sheets( 0 )
osourcesheet.name="SheetName"
End If
End Sub
I am sorry for my bad english