Moin!
ich habe eine Verbindung zu Excel erstellt und möchte bedingte Formatierungen für den Hintergrund definieren.
Hier mein Code - in der Hoffnung nichts vergessen zu haben bei den Ausschnitten.
Das Problem ist nun, dass immer nur eine Farbe im Regelwerk auftaucht und der Rest nur weiß ist.
Kann mir einer von Euch weiterhelfen ?
Gruß Jan
ich habe eine Verbindung zu Excel erstellt und möchte bedingte Formatierungen für den Hintergrund definieren.
Hier mein Code - in der Hoffnung nichts vergessen zu haben bei den Ausschnitten.
VB.NET-Quellcode
- Imports Microsoft.Office.Interop
- Imports xls = Microsoft.Office.Interop.Excel
- ...
- Private Sub EBL_Insp_Crawler_Work(Laufwerk As String)
- Const k_Text_undef As String = "./."
- Const k_Text_OK As String = "OK"
- Const k_Text_ng As String = "n.g."
- Const k_Text_Err As String = "Fehler!"
- Const k_Color_Green As Integer = 5296274
- Const k_Color_Red As Integer = 255
- Const k_Color_Yellow As Integer = 65535
- Const k_Color_Blue As Integer = 15773696
- ' öffnen der Excel-Datei
- Dim xls_Appl As Excel.Application
- Dim xls_Mappe As Excel.Workbook ' Excel Arbeitsmappe
- Dim xls_Blatt As Excel.Worksheet ' Excel Blatt ( Tabelle)
- xls_Appl = CType(CreateObject("Excel.Application"), Excel.Application)
- xls_Appl.Visible = False
- xls_Mappe = xls_Appl.Workbooks.Add 'Hier kommt kein gültiges Objekt zurück
- 'xls_Mappe = xls_Appl.Workbooks.Open(FullPathStundenZettel)
- With xls_Blatt
- Const k_Verz_XML As Integer = 2
- BedFormatBackground(xls_Blatt, k_Verz_XML, "RED", k_Color_Red)
- BedFormatBackground(xls_Blatt, k_Verz_XML, "GREEN", k_Color_Green)
- BedFormatBackground(xls_Blatt, k_Verz_XML, "BLUE", k_Color_Blue)
- end with
- End Sub
- Private Sub BedFormatBackground(ByRef sheet As Excel.Worksheet, iSpalte As Integer, sValue As String, Color As Integer)
- Dim ColLetter As String = _XLS_Write.Ziffer2ExcelColumn(iSpalte)
- Dim r As Object
- Try
- r = sheet.Range(ColLetter & ":" & ColLetter).Select()
- With sheet.Range(ColLetter & ":" & ColLetter)
- .FormatConditions.Add(Type:=Microsoft.Office.Interop.Excel.XlFormatConditionType.xlTextString, String:=sValue, TextOperator:=2)
- .FormatConditions(.FormatConditions.Count).SetFirstPriority()
- .FormatConditions(.FormatConditions.Count).Interior.PatternColorIndex = Microsoft.Office.Interop.Excel.Constants.xlAutomatic
- .FormatConditions(.FormatConditions.Count).Interior.ThemeColor = Microsoft.Office.Interop.Excel.XlThemeColor.xlThemeColorAccent3
- .FormatConditions(.FormatConditions.Count).Interior.TintAndShade = 0.0
- End With
- Catch ex As Exception
- Dim TryReport As New EBL.Service.TryCatchReport
- TryReport.Show("unerwarteter Fehler in EBL.Verwaltung > INSP_Crawler > BedFormatBackground" & vbCrLf & ex.ToString)
- End Try
- End Sub
Das Problem ist nun, dass immer nur eine Farbe im Regelwerk auftaucht und der Rest nur weiß ist.
Kann mir einer von Euch weiterhelfen ?
Gruß Jan