So I was coding an export for a spreadsheet that included conditional formatting (ContainsText in this case). I was completely befuddled when after exporting and then reimporting I got an ArgumentOutOfRange exception when the importing logic attempted to access the styling property on a cell or the ConditionalFormatting property on the worksheet.
After much dithering about not really knowing what I was doing I discovered that I was setting the foreground/background colours in the conditional formatting's style using Color.FromArgb(int, int, int, int), where the first parameter is the colour's alpha value.
Me being a fool, I assumed the first parameter was a double that went from 0 to 1, so I set it to 1. For some reason unknown to me, the alpha being 1 meant that when I tried to access style properties on a reimport it threw the exception "Index and length must refer to a location within the string. Parameter name: length".
When I realised my error and changed the 1 to 255 everything worked fine on import. Further investigation leads me to believe that importing a previously exported document that set a colour with an alpha of less than 16 brought about the exception mentioned above.
I have no idea if this is only with conditional formatting or styling across the workbook in general, but I though I should give you a heads up. While it's a rare scenario, it may be something you want to look into.
Thanks for your time.
After much dithering about not really knowing what I was doing I discovered that I was setting the foreground/background colours in the conditional formatting's style using Color.FromArgb(int, int, int, int), where the first parameter is the colour's alpha value.
Me being a fool, I assumed the first parameter was a double that went from 0 to 1, so I set it to 1. For some reason unknown to me, the alpha being 1 meant that when I tried to access style properties on a reimport it threw the exception "Index and length must refer to a location within the string. Parameter name: length".
When I realised my error and changed the 1 to 255 everything worked fine on import. Further investigation leads me to believe that importing a previously exported document that set a colour with an alpha of less than 16 brought about the exception mentioned above.
I have no idea if this is only with conditional formatting or styling across the workbook in general, but I though I should give you a heads up. While it's a rare scenario, it may be something you want to look into.
Thanks for your time.