Saving a WK1 file as a .CSV (or something)

S

Sara

I am trying to develop an application in VB.net that will take a .WK1
file and save it as a .csv or .txt file. It was suggested that
somebody on this board may be able to show me how to do it using VB in
Excel, and then someone on the VB.Net board can convert that to .NET.
I know this sounds terribly convoluted, but if anyone can tell me how,
in Excel, I can programmaticaly open a .WK1 file and then save it as a
..csv file, I would be eternally grateful.
Thanks,
Sara
 
S

Sara

I know that it's tacky to reply to your own post, but I
was able to get a great answer to this from Fergus Coon in
the VB.NET newsgroup, and I thought that I'd post it for
anyone that was looking for an answer:

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


P.S Have to add MSOffice references for this to work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top