I am currently writing a program in windows forms with vb.net and an SQL back end. The program is taking customer created Engineering Change Orders, Bill of Material updates, and recreating a custom template that we upload to our Oracle system to create the BOM changes. The customer sends us an excel spreadsheet with the updated BOMs. Items added to the BOM appear in red text and items being removed from the BOM are in red text with a strike through the text. My program is reading down the excel column and adding the item numbers to an SQL table that holds all the new BOMs. My problem is the removed items, items that appear in red with a strikethrough the text, are also being added. I need a way to detect if the font has a strike through so that I can stop them from being added to the SQL table. However, I can't find any way to detect text formatting on the excel sheet. I know you can detect text formatting with VBA inside of an excel macro but I can't find anything on how to do this with VB.NET on windows forms apps.
I thought the code would look something like this however "Characters" is not a legitimate option here.
If xlworksheet.cells(1,1).characters.font.strikethrough = true then
next
end if
Is there anyway to detect text formatting options like strikethrough with VB.NET inside windows forms.
We can use excel interop to do this. We can look for Font.Strikethrough. The following code worked for me.
Dim range as excel.Range = xlworksheet.cells(1,1)
If range.Font.Strikethrough = true then
'Strike through detected, do something
else
'No strike through detected, do something else
End If
The above code looked at the excel cell (1,1) or A1 and checked to see if it had a strike through or not. I confirmed this solution by applying a strikethrough in text on this cell and resaving the file and running the code again without a strike through.