Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loop through an Excel range and write to the cells in .net [closed]

I am trying to loop through a range and write values into the cells of that range. I'm getting an exception when giving the instantiated range an actual value.

what am I doing wrong?

int fieldcount = dr.FieldCount;
for (int f = 0; f < fieldcount; f++) {
    Excel.Range chartRange;
    int count = 1;
    chartRange = sheet.Range["B43:043"];

    foreach(Excel.Range cell in chartRange.Cells) {
        Debug.Print(cell.Address, cell.Value);
    }
}

I've also tried setting the range as follows:

sheet.get_Range("B43", "043");

The exception I'm getting is Exception from HRESULT: 0x800A03EC

like image 841
Eric Avatar asked Jan 23 '26 09:01

Eric


1 Answers

I Think you have a typo in your range. "043" (the number 43 with a leading zero) is not a valid cell reference. Are you intending: sheet.Range["B43:O43"] ?

like image 71
Eddy Avatar answered Jan 25 '26 00:01

Eddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!