Search code examples
c#epplusoff-by-one

EPPlus Off-by-One Fix


I'm updating some old code, and want to replace some code to create excel documents with EPPlus. The problem is my old code indexes things from [0, n-1] and EPPlus indexes from [1, n].

Is there any way to account for this, other than to manually increment all cell addresses by [1,1]?


Solution

  • So an interface which reads in indices at [0,n-1] and then increments the values before calling the appropriate methods probably would have worked, but for personal reasons, I couldn't use this approach.

    Things that helped me:

    • Where I was using variables purposed for indexing, I could increase their initial value by 1.
    • Large sections of relatively repetitive code (same operations, different cell ranges) into small loops where there were less values to manage.
    • Helper methods for commonly used formats for were also very helpful in preventing me writing the same range multiple times.

    Beyond that, however, I unfortunately didn't find a simpler way than to add [1,1] to everything.