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

  • SEARCH
  • Home
  • 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 8731329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:12:41+00:00 2026-06-13T09:12:41+00:00

So, I am trying to convert some xls files to a csv, and everything

  • 0

So, I am trying to convert some xls files to a csv, and everything works great, except for one part. The SaveAs function in the Excel interop seems to export all of the rows (including blank ones). I can see these rows when I look at the file using Notepad. (All of the rows I expect, 15 rows with two single quotes, then the rest are just blank). I then have a stored procedure that takes this csv and imports to the desired table (this works on spreadsheets that have been manually converted to csv (e.g. open, File–> Saves As, etc.)

Here is the line of code I am using for my SavesAs in my code. I have tried xlCSV, xlCSVWindows, and xlCSVDOS as my file format, but they all do the same thing.

wb.SaveAs(aFiles(i).Replace(".xls", "B.csv"), Excel.XlFileFormat.xlCSVMSDOS, , , , False) 'saves a copy of the spreadsheet as a csv

So, is there some additional step/setting I need to do to not get the extraneuos rows to show up in the csv?

Note that if I open this newly created csv, and then click Save As, and choose csv, my procedure likes it again.

  • 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-06-13T09:12:42+00:00Added an answer on June 13, 2026 at 9:12 am

    When you create a CSV from a Workbook, the CSV is generated based upon your UsedRange. Since the UsedRange can be expanded simply by having formatting applied to a cell (without any contents) this is why you are getting blank rows. (You can also get blank columns due to this issue.)

    When you open the generated CSV all of those no-content cells no longer contribute to the UsedRange due to having no content or formatting (since only values are saved in CSVs).

    You can correct this issue by updating your used range before the save. Here’s a brief sub I wrote in VBA that would do the trick. This code would make you lose all formatting, but I figured that wasn’t important since you’re saving to a CSV anyway. I’ll leave the conversion to VB.Net up to you.

    Sub CorrectUsedRange()
        Dim values
        Dim usedRangeAddress As String
        Dim r As Range
        'Get UsedRange Address prior to deleting Range
        usedRangeAddress = ActiveSheet.UsedRange.Address
        'Store values of cells to array.
        values = ActiveSheet.UsedRange
        'Delete all cells in the sheet
        ActiveSheet.Cells.Delete
        'Restore values to their initial locations
        Range(usedRangeAddress) = values
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert some pre-existing html/JavaScript files to Flex. I tried making
I'm trying to convert some old 32 bit code to 64 bit. One of
I have a problem with the preg_replace function, I am trying to convert some
I'm trying to convert some code that worked great in VB, but I can't
I'm trying to convert some Excel formulas into C# code, and I'm kind of
I'm trying to convert some simple .htaccess rewrites into web.config xml; all is well
Background : I'm trying to convert some JavaScript code which uses the the Crossfilter
I'm trying to convert some VB.net code into C# and having issues trying to
I am trying to convert some ExtJS 3.3 to 4.0. In ExtJS 3.x I
I am trying to convert some pages from my app to use cfc's, and

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.