Export from Excel to text file

dsm1995gst

Member
Joined
Apr 29, 2011
Messages
16
Programming Experience
1-3
I've been working on this for a little while now, and have tried a bunch of different things that seem like they should work, but I can't seem to get it.

Basically I just need to read a specific column from an Excel spreadsheet and have it write to a text file.

Is there a simple way to do this?
 
Add a reference to excel in your project.

VB.NET:
Import Microsoft.Office.Interop

Now you can write some code that loads an excel spreadsheet, loops through each row in a column, and now there should be a plethora of ways to get this to text:

Dim xl as New Excel.Application
Dim xlBook as Excel.Workbook = xl.Workbooks.Open("Yourworkbook.xls")
Dim xlSheet as Excel.worksheet = xlBook.Worksheets("Yourworksheet")
Dim sw as New System.IO.Streamwriter("c:\OutputText.txt")
For x as integer = 1 to lastrow
sw.WriteLine(xlSheet.cells(x, 1).Value)
Next x


The above code will open an excel sheet loop through the rows and will write the values in the first column to a text file one line for each row.
 
Last row is something I just made up you will need to specify an end for the loop. As far as the column it is line 6 of my code sample "cells(x, 1)" -- 1 is the column.
 
Back
Top