Home > Blockchain >  How to match entire cell content when using Cells.Replace() on a WorkSheet using C#
How to match entire cell content when using Cells.Replace() on a WorkSheet using C#

Time:10-21

I want to replace every cell in my worksheet that contains just zero with blank.

This code will replace all zeros with blank but it will find all zeros i.e. 12045 will become 1245. I need some parameter that will match the entire cell content to see if the cell only contains a single zero.

ws.Cells.Replace(0, "");

CodePudding user response:

If you want to replace whole word, then pass additional parameter to Cells.Replace() i.e XlLookAt.xlWhole

 ws.Cells.Replace(0, "", XlLookAt.xlWhole);
                       //^^^^^^^^^^^^^^^^ This needs to be added.

XlLookAt Enum:

Specifies whether a match is made against the whole of the search text or any part of the search text.

  • Related