Converting a WK1 file to csv (or something)

  • Thread starter Thread starter Sara
  • Start date Start date
S

Sara

I would like my app to read from a report that is currrently issued in
..WK1 format (Lotus 123). Because I don't know how to read from this
format, I would like to be able to first save it as a .csv or .txt
file. Is it possible to do that in VB.NET? The machine that the app
will reside on does have MSOffice.
I am quite a newbie to .NET, so if you could provide an example, I
would be forever grateful.

Thanks,
Sara
 
Hi Sara,
I think it is possible, but just as an advice, ask it too in the Excel
newsgroup.
Excel can read (as the options are set) a WK1 format and then as you said,
it is a good idea to save it as CSV
In the Excel group they give you probably an answer in VBA.
I have seen in this newsgroup many examples how people did use VBA code in
VB.net.
If you than are not able to change the VBA to VB.net, drop it here, there
will always be someone who helps you.

Just an advice
Cor
 
Hi Sara,

It's funny how things appear in clusters. Just two days ago I answered the
same query - except that it was converting an xls file to a csv file. You can
use this to convert your wks to a Csv or to an Excel spreadsheet (or any other
format supported, in fact).

As you san see it's only about three lines of useful code - but with a lot
of packaging. You'll get an Excel dialogue about overwriting if the target
file already exists.

Regards,
Fergus

<code>
Imports System.Runtime.InteropServices

Public Module ExcelUtils
Public Const xlCsv As Integer = 6
Public Const xlNormal As Integer = -4143
Public Const xlXls As Integer = -4143 'Alias for xlNormal

Public Sub ConvertFile (sSrcFilePath As String, _
sDestFilePath As String, xlOutputFormat As Integer)
Dim oExcel As Excel.Application
Dim oWorkSheet As Worksheet

Try
oExcel = New Excel.Application
oExcel.Visible = True 'Optional but good for debugging.

oExcel.Workbooks.Open (sSrcFilePath)
oWorksheet = DirectCast (oExcel.ActiveSheet, Excel.Worksheet)
oWorksheet.SaveAs (sDestFilePath, xlOutputFormat)

Catch
Dim Up As New Exception ("Bad file - Uuurghh")
Throw Up

Finally
If oWorksheet Is Nothing = False Then
Marshal.ReleaseComObject (oWorksheet)
End If
If oExcel Is Nothing = False Then
oExcel.Quit
Marshal.ReleaseComObject (oExcel)
End If
End Try

End Sub
End Module
</code>
 
Hi Fergus,
I knew, but I could not find it any more even not on Google, seems it had
another header or so.
Cor
 
Fergus, you are da Bomb! Thanks, and it works beautifully.
Is there anyway to keep the alert from appearing? The one
that tell you that the sheet is not in Excel format, press
yes to save as excel, no to keep as formatted, etc?? I
would like it to be transparent to the users. I can make
sure that the output file does not exist before it's
converted, but I'd like to supress the formatting alert as
well.
Thank you,Thank you,Thank you,
Sara
 
Hi Sara,

I am da Bomb!! ;-))
And <you> are most welcome.

I haven't tried this but it was mentioned in another post:

You can tell Excel not to display alerts once you have it started.

oExcel = New Excel.Application
oExcel.DisplayAlerts = False

Regards,
Fergus
 
Hi Sara,

I am da Bomb!! ;-))
And <you> are most welcome.

I haven't tried this but it was mentioned in another post:

You can tell Excel not to display alerts once you have it started.

oExcel = New Excel.Application
oExcel.DisplayAlerts = False

Regards,
Fergus
 
Back
Top