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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:04:32+00:00 2026-05-28T01:04:32+00:00

I am exporting to Excel using C# and I get this error on some

  • 0

I am exporting to Excel using C# and I get this error on some records.

The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data

From googling it I saw it has to do with the size limitation, but I couldn’t find a workaround. Any ideas?

Requested Code:

string lFilename = Leads.xls";
string lDistributorFolder = Server.MapPath(".") + "\\Portals\\0\\Distributors\\" + _currentUser.UserID.ToString() + "\\";
string lTemplateFolder = System.Configuration.ConfigurationManager.AppSettings["Templates"];
System.IO.Directory.CreateDirectory(lDistributorFolder);

File.Copy(lTemplateFolder + lFilename, lDistributorFolder + lFilename, true);
string lConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + lDistributorFolder + "\\" + lFilename + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";
DbProviderFactory lFactory = DbProviderFactories.GetFactory("System.Data.OleDb");
int lSequence = 0;

using (DbConnection lConnection = lFactory.CreateConnection())
{
    lConnection.ConnectionString = lConnectionString;
    lConnection.Open();

foreach (GridDataItem lItem in grdLeadList.Items)
  {
    lSequence++;

    using (DbCommand lCommand = lConnection.CreateCommand())
      {
           lCommand.CommandText = "INSERT INTO [ColderLeads$] ";
           lCommand.CommandText += "(F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21) ";
           lCommand.CommandText += "VALUES(";
           lCommand.CommandText += "\"" + lSequence.ToString() + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gLeadNumber].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gSource].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gAccountName].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gCreatedOn].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gContactFullName].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gPriority].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gStreet1].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gStreet2].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gZIP].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gCity].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += "\"" + lItem.Cells[_gState].Text.Replace(" ", " ") + "\",";
           lCommand.CommandText += ")";
           lCommand.ExecuteNonQuery();
         }
      }

     lConnection.Close();
  }

Thanks!

  • 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-28T01:04:32+00:00Added an answer on May 28, 2026 at 1:04 am

    Are you using Excel 2003? If so, there is a limitation on the size of the Excel Worksheet. It is 65,536 rows by 256 columns. See the following link for more info.

    There is also a limitation on the Column Width. This is 255 characters. Try trimming all your fields in C# before exporting it to Excel. What you can also do is when the workbook has reached the maximum row length, create another Worksheet.

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

Sidebar

Related Questions

I am using a Windows application for exporting a data table to Excel. It's
I'm exporting data programatically from Excel to SQL Server 2005 using SqlBulkCopy. It works
In ASP.NET, I am exporting some data to Excel by simply binding a DataSet
Exporting some data from mysql to a csv file using FasterCSV. I'd like the
I am currently exporting data from php to excel using the code as below:
Using ColdFusion and Microsoft SQL we are exporting data to an Excel Spreadsheet using
When exporting my simple data report to Excel (Using ReportViewer in localmode) I can
I am exporting my data into Excel Using Open XML . now i want
We're exporting a set of data using .net interop to Excel and our template
I'm exporting data form my C# application to an Excel file using Office Interop.

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.