0

I am new to C# and I wanted to ask a question: I have an Excel file in which the first column is number of row second column is variable x(number) and third column is variable y(number) and I want to show variable x and y in textbooks, The rest of code that opens Excel is OK because it's working in another form, I use this code for it:

for (int i = 1; i <= 11; i++) //rowCount
{
    if (xlRange.Cells[i, 1] != null && xlRange.Cells[i, 2].Value2 != null)
    {
        int x = xlRange.Rows[i - 1].Cells[1].Value = xlRange.Cells[1].Value2;
        int y = xlRange.Rows[i - 1].Cells[2].Value = xlRange.Cells[2].Value2;

        hodnotax.Text = x.ToString();
        hodnotay.Text = y.ToString();
    }
}

but in the final step, I get this error:

System.Runtime.InteropServices.COMException: 'Value-based exception HRESULT: 0x800A03EC'

and I don't know what to do with that code to make it work, thanks for every answer

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
Martin Kavka
  • 11
  • 1
  • 2

1 Answers1

0

One possible problem would be the folder of your Excel Document. If it is somehow located in x86 then change the location to a non-admin folder.

If it didn't work, save your Excel in this format : X.xlsx

More solutions on this thread : Exception from HRESULT: 0x800A03EC Error Good luck!

apm11
  • 7
  • 4