Solved

Exception from HRESULT: 0x800A03EC

Posted on 2007-03-30
3
8,023 Views
Last Modified: 2009-05-06
System.Runtime.InteropServices.COMException was unhandled by user code
  ErrorCode=-2146827284
  Message="Exception from HRESULT: 0x800A03EC"
  Source=""
  StackTrace:
       at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
       at Microsoft.Office.Interop.Excel.Range.get_Resize(Object RowSize, Object ColumnSize)
       at ExportExcel.Export_To_Excel(DataTable dtSource, String sFileName) in C:\SourceControl_mcupryk\InHouseDev\APPS\MKT0003 - CustomerList\src\CustomerList\App_Code\BOL\ExportExcel.vb:line 42
       at MainPage.cmdProceed_Click(Object sender, ImageClickEventArgs e) in C:\SourceControl_mcupryk\InHouseDev\APPS\MKT0003 - CustomerList\src\CustomerList\MainPage.aspx.vb:line 83
       at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
       at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Sub Export_To_Excel(ByVal dtSource As System.Data.DataTable, ByVal sFileName As String)

        Dim iRowCount As Integer = dtSource.Rows.Count
        Dim iColCount As Integer = dtSource.Columns.Count
        Dim oData(iRowCount, iColCount) As Object

        Dim iRow As Integer, iCol As Integer
        For iRow = 0 To iRowCount - 1
            For iCol = 0 To iColCount - 1
                oData(iRow, iCol) = dtSource.Rows(iRow).Item(iCol)
            Next
        Next

        ' Start Excel and get Application object
        Dim oExcel As Excel.Application = New Excel.Application()
        'oExcel.Visible = True  ' Make visible

        ' Get a new workbook
        Dim oBook As Excel._Workbook = CType(oExcel.Workbooks.Add(Missing.Value), Excel._Workbook)
        Dim oSheet As Excel._Worksheet = CType(oBook.ActiveSheet, Excel._Worksheet)

        Dim oRange As Excel.Range = oSheet.Range("A1")
        'oRange = oRange.Resize(iRowCount, iColCount) ====> Crashes here,
        oRange.Value = oData

        oSheet.SaveAs(sFileName)
        oExcel.Workbooks.Close()
        oExcel.Quit()

        oBook = Nothing
        oSheet = Nothing
        oExcel = Nothing
    End Sub
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
levyuk earned 500 total points
ID: 18831537
check that iRowCount and iColCount are not out of range because in the loop you do -1 but not when you do oRange.Resize()
0
 

Author Comment

by:mathieu_cupryk
ID: 18833289
Ok do you have some classes to handle converting datasets or datatables to excel spreadsheet with large amounts of data in vb.net or C#. I would greatly appreciate it.
0
 
LVL 7

Expert Comment

by:levyuk
ID: 18837490
I don't sorry, I try to stay away from putting large data into excel because it takes ages to create all the rows and workbooks and stuff. Thanhks for the points though dude
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
LINQ Select all records by MAX data syntax help 1 50
Converting PHP triple des decrypt to c# 9 168
Trigger C# code inside the SQL Server 6 57
c# ftp code 3 56
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question