Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

Detect Strikethrough in Excel Cell with VB.NET on a Windows Forms App

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.

question from:https://stackoverflow.com/questions/65846846/detect-strikethrough-in-excel-cell-with-vb-net-on-a-windows-forms-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...