9

I just started implementing this to populate an Excel sheet with some data:

using OfficeOpenXml; //.. ExcelWorksheet VerificationSheet_Sheet4 = package.Workbook.Worksheets.Add("SheetTitleHere"); int row = 0, col = 0; VerificationSheet_Sheet4.Cells[row + 1, col].Value = "AnyStringHere"; // error here 

However it pops an error saying column is out of range. Why and how can I fix that?

2 Answers 2

25

Excel worksheets use 1 based indexing rather than zero based. Thus columns and rows both start at 1 and not 0.

Sign up to request clarification or add additional context in comments.

Comments

2

As per the elaboration by @Darren Young Excel uses 1 based indexing thats where the issue is.

 using OfficeOpenXml; //.. ExcelWorksheet VerificationSheet_Sheet4 = package.Workbook.Worksheets.Add("SheetTitleHere"); int row = 1, col = 1; VerificationSheet_Sheet4.Cells[row + 1, col].Value = "AnyStringHere"; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.