Solved

Exception from HRESULT: 0x800A03EC

Posted on 2007-03-30
3
7,965 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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 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