I keep getting System.Runtime.InteropServices.COMException (0x80028018): Old format or invalid type library. error

1

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()
vb.net
excel
listview
asked on Stack Overflow Aug 26, 2016 by Tassisto • edited Aug 26, 2016 by Tassisto

1 Answer

0

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)
answered on Stack Overflow Aug 26, 2016 by Jim Hewitt • edited Oct 18, 2016 by Jim Hewitt

User contributions licensed under CC BY-SA 3.0