简体   繁体   中英

Writing to excel file and using too many rows

I have a problem with writing from a VB.NET application to excel. I am basically trying to write the numbers 1-2000000 into excel. The problem is that excel can only hold 1048575 rows and so I cut it at 1000000 to make it simpler. I am trying to write the first million numbers into the first column and the second million into the second column. eg

1 | 1000001

2 | 1000002

... | ...

1000000 | 2000000

For i = 1 to 2000000 Step 1
    'sheet.cells(row,column) these are the parameters for cells()
    sheet.cells(i Mod 1000000 , 2 * Math.floor(i / 1000000) + 1)
Next

I run the program and I get an error:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Exception from HRESULT: 0x800A03EC

Where am I wrong? I've tried using google, and it seems that the problem is that its trying to write into a cell thats not there, and I can't see where I'm going wrong.

Thanks in advance,

Rinslep

It turns out that excel is not 0 based and so:

((i-1) Mod 1000000) + 1

this fixes it.

thanks user3964075 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM