I try to update the excel sheet rows with their corresponding row colors from the ListView - objLv
objLv = ListView
I added a Reference to System.Drawing.dll - Runtime Version v2.0.50727 - Version 2.0.0.0
The error occurs at 'workbook.Styles.Item(i).Interior.Color... So it's the 6th line of the code below. I applied some solutions but can't get the problem solved.
Dim oldCI = New System.Globalization.CultureInfo("en-US")
'Me.sCloseDoc(strXLSFile)
Dim workbook As Excel.Workbook = Me.fOpenXlsFile(strXLSFile)
For i As Int32 = 0 To objLv.Items.Count - 1
workbook.Styles.Item(i).Interior.Color = objLv.Items(i).BackColor
Next
workbook.Save()
The Styles collection is not 0 based.
Try workbook.Styles.Item(i+1).Interior.Color = objLv.Items(i).BackColor
.
Also, as David mentioned in the comments, you'll need to reset the culture after saving the WorkBook as follows:
System.Threading.Thread.CurrentThread.CurrentCulture = CType(oldCI, CultureInfo)
User contributions licensed under CC BY-SA 3.0