Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6362451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:54:35+00:00 2026-05-24T23:54:35+00:00

There is a program that reads an Excel file using OLEDB and converts it

  • 0

There is a program that reads an Excel file using OLEDB and converts it to a tab delimited text file. This loop handles the conversion.

While reader.Read
            Dim count As Integer = 0
            Try
                While (True)
                    temp = reader(count).ToString + ControlChars.Tab
                    output_file.Write(temp)
                    count += 1
                End While
            Catch ex As Exception
                output_file.WriteLine()
            End Try


        End While

Not the most elegant code for sure, but it reads in each cell one by one, then throws an exception at the end of the row to write a newline. The only problem is that it skips the first line of the Excel document. Any idea why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:54:35+00:00Added an answer on May 24, 2026 at 11:54 pm

    For a more elegant solution, try this:

    While reader.Read()
    
        For i As Integer = 0 To reader.FieldCount - 1
            output_file.Write(reader(i).ToString() + ControlChars.Tab)
        Next
    
        output_file.WriteLine()
    End While
    

    Read each line from the reader, and process the fields in the row in a FOR loop, using the number of fields in the row (.FieldCount).

    After each FOR loop is complete, end the line in the file.

    Repeat for each row in the reader.

    It’s good practice to not use exceptions to handle events in code that can otherwise be handled (e.g., throwing a handling a FileNotFoundException – or throwing one – rather than simply doing a File.Exits check).\

    UPDATE
    Did a little googling, and it appears that you can include/exclude the header via the connection string:

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";

    Note the HDR=Yes part. According to Connection strings for Excel this is used to indicate whether or not the first row is the header.

    Another thing you might try is seeing if the reader’s fields have values in their Name property, using reader.GetName(int index), where index is the zero-based ordinal of the column (field).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that reads a huge text file (line by line) and
It's a program that reads student data from a text file and displys it
Is there a way using JNI and C# code to create a program that
Currently, I have a program that reads a file and uses an XMLTextWriter to
I have a VB.Net program that reads in a flat file, and then parses
I have a program that reads a bunch of text and analyzes it. The
I have a program that is using the excel interop routines to generate a
I am writing a program that reads data packets from a file, and assigns
I have a program that reads and draws an SVG file in a java
I'm writing a program that reads from a list of files. The each file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.