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 5966331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:47:03+00:00 2026-05-22T19:47:03+00:00

I’m importing data from an excel file and I just noticed that some cells

  • 0

I’m importing data from an excel file and I just noticed that some cells are becoming ” ” after the import

Here’s the code I’m using

                FileUploadExcel.SaveAs("C:\\datatop.xls");
                string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\1.xls;Extended Properties=Excel 8.0;";


                using (OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    connection.Open();
                    OleDbCommand command = new OleDbCommand("Select MONTH, QTY FROM [Sheet1$]", connection);
                    DataTable tb = new DataTable();
                    using (System.Data.Common.DbDataReader dr = command.ExecuteReader())
                    {
                        tb.Load(dr);
                    }
                    gv.DataSource = tb;
                    gv.DataBind();
                }

The column in question is QTY which contains:

12
14
15
11
19k/yr
4
2

It becomes a space on my gridview after the import. All other cells are displaying just fine on the gridview.

OUTPUT in GridView:

12
14
15
11

4
2

Any ideas?

  • 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-22T19:47:03+00:00Added an answer on May 22, 2026 at 7:47 pm

    When using OLEDB with Excel, the data type of a column is determined by the first few items in each column. In your case, the first few items in the column are numbers, so it assumes the column is of type int. If you want the column to be considered text, you need to make sure you have some dummy rows at the top with data that ensures the right data types, then filter out those rows once the data is read into the data table. I know it’s a cluge, but it should work.

    Edit – Alternative: Using Excel Interop/COM to fill a DataTable

    using Microsoft.Office.Interop.Excel;
    using Sd = System.Data;
    
    private void FillTableData(Sd.DataTable table, Worksheet worksheet, Range cells)
    {
        using (var com = new ComObjectManager())
        {
            var firstCell = GetFirstCell(com, cells);
            var beginCell = com.Get<Range>(() => (Range)cells.Item[2, 1]);
            var endCell = GetLastContiguousCell(com, cells, firstCell);
            if (beginCell.Value == null) return;
            var range = GetRange(com, cells, beginCell, endCell);
            var data = (object[,])range.Value;
            var rowCount = data.GetLength(0);
            for (var rowIndex = 0; rowIndex < rowCount; rowIndex++)
            {
                var values = new object[table.Columns.Count];
                for (var columnIndex = 0; columnIndex < table.Columns.Count; columnIndex++)
                {
                    var value = data[rowIndex + 1, columnIndex + 1];
                    values[columnIndex] = value;
                }
                table.Rows.Add(values);
            }
        }
    }
    
    private Range GetFirstCell(ComObjectManager com, Range cells)
    {
        return com.Get<Range>(() => (Range)cells.Item[1, 1]);
    }
    
    private Range GetLastContiguousCell(ComObjectManager com, Range cells, Range beginCell)
    {
        var bottomCell = com.Get<Range>(() => beginCell.End[XlDirection.xlDown]);
        var rightCell = com.Get<Range>(() => beginCell.End[XlDirection.xlToRight]);
        return com.Get<Range>(() => (Range)cells.Item[bottomCell.Row, rightCell.Column]);
    }
    

    ComObjectManager – ensures that COM objects are properly disposed after being used

    using System;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    
    public class ComObjectManager : IDisposable
    {
        private Stack<object> _comObjects = new Stack<object>();
    
        public TComObject Get<TComObject>(Func<TComObject> getter)
        {
            var comObject = getter();
            _comObjects.Push(comObject);
            return comObject;
        }
    
        public void Dispose()
        {
            while (_comObjects.Count > 0)
                Marshal.ReleaseComObject(_comObjects.Pop());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a bunch of posts stored in text files formatted in yaml/textile (from
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the

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.