473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Export data to excel in windows Forms Application

1
hi,

i am using windowsforms application and i have one button for import datagridview to ms excel format... its working but when i am adding large amount of data it shows some error... the error is

COMException: Exception from HRESULT: 0x800A03EC.

How shall i solve this error? How shall i get solution? Tell me the solution of this problem...

Thanks in advance...
Expand|Select|Wrap|Line Numbers
  1.     Excel.Application oxl;
  2.     Excel.Workbook wbook;
  3.     Excel.Worksheet wsheet;
  4.     Excel.Range range;
  5.  
  6.     private void button1_Click(object sender, EventArgs e)
  7.     {
  8.         oxl = new Excel.Application();
  9.         oxl.Visible = true;
  10.         oxl.DisplayAlerts = false;
  11.  
  12.  
  13.         wbook = oxl.Workbooks.Add(Missing.Value);
  14.  
  15.         wsheet = (Excel.Worksheet)wbook.ActiveSheet;
  16.         wsheet.Name = "Customers"; 
  17.  
  18.  
  19.  
  20.         DataTable dt = InstituteTypeDetail();
  21.  
  22.         int rowCount = 1;
  23.         foreach (DataRow dr in dt.Rows)
  24.         {
  25.             rowCount += 1;
  26.             for (int i = 1; i < dt.Columns.Count + 1; i++)
  27.             {
  28.                 // Add the header the first time through
  29.                 if (rowCount == 2)
  30.                 {
  31.                     wsheet.Cells[1, i] = dt.Columns[i - 1].ColumnName;
  32.                 }
  33.                 wsheet.Cells[rowCount, i] = dr[i - 1].ToString();
  34.             }
  35.         }
  36.  
  37.         range = wsheet.get_Range(wsheet.Cells[1, 1],
  38.                       wsheet.Cells[rowCount, dt.Columns.Count]);
  39.         range.EntireColumn.AutoFit();
  40.  
  41.  
  42.         wsheet = null;
  43.         range = null;
  44.  
  45.     }
Mar 9 '10 #1
1 6593
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 9 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: frankvfox | last post by:
I need a code sample using VB ASP.Net 2003 which exports a tab delimited text file resident on the server into an Excel spreadsheet which will be saved through the browser to the client's local...
0
by: Max Mayer | last post by:
Hello everybody, I have implemented a windows form in C# .NET to export data from a listbox to Excel. I work on a Windows XP machine with Office 97 and .NET framework 1.1 SDK installed. I use...
0
by: Max Mayer | last post by:
Hello everybody, I have implemented a windows form in C# .NET to export data from a listbox to Excel. I work on a Windows XP machine with Office 97 and .NET framework 1.1 SDK installed. I use...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
4
by: Agnes | last post by:
I can export the data to excel, but it is really really slow. need 5-6 mins to export 30 fields (a hundred records) . for my old vfp application, less than 3 minutes. for 500-800 records. Does any...
13
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
4
by: Agnes | last post by:
I searched from previous post and got that there is a solution which export the data to export without using Excel auotmation. However, my database is SQL server, How can I amend...
3
by: RobinAG | last post by:
Hello I've created an Excel spreadsheet to export word count and project count per week, per language, for a Translation company. This code works, however, only for one language at a time. The...
3
by: jmarcrum | last post by:
I want to export a report (that contains two separate queries, 1. Current year data, and 2. split-year data) from access into excel, but everytime I run my code and export the data to excel, it looks...
2
by: TG | last post by:
Hi! I am trying to export only the visible columns from a datagridview in my windows form in VB 2008. Should't it be no comma after the first row where the headers are? Also should...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.