Click here to Skip to main content
15,887,945 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I am working on exporting data from db to excel.
I need to make some changes in the data retrieved in the cells.
To be precise i need to replace some strings with other.

e.g. 'ABB' needs to be replaced by 'AB'in the generated excel
'MNODays' needs to be replaced by 'LM Days'
'MN' needs to be replaced with 'LM Hours'

usinf Replace function I have tried the following:

<pre>Excel.Range rg1;
rg1 = excelSheet.get_Range(B:B, Type.Missing);
rg1.Cells.Replace("MNODays","LM Days", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
rg1.Cells.Replace("MN","LM Hours", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);




The problem is that its exact match is not being taken and replaced. As in 'MNODays' gets replaced with 'LLM Days Hours' mixing it with the characters in second separate string 'MN'.

Is there any other way to achieve the exact match functionality?
Please help

Thanks
Posted

1 solution

This is all guesswork -)

Are you sure that is actually what you are seeing... i.e. .you start with
"MNODays"
and finish with
"LLM Days Hours"

If so, then something seems to me to be horribly wrong!
I'd break it down and just have the first replace and look at the results - if you get "LMDays" then the implication would seem to be that replacing "MN" by "LM Hours" on a cell with a value "LMDays" produces "LLM Days Hours" which is madness.

Are you sire you don't mean that the "MN" bit of "MNODays" gets replaced by "LM Hours" leaving you with "LM HoursODays"?

I think you will find that one of the parameters you are setting to "Type.Missing" can be set to tell the function to replace the whole cell value, rather than any part, if that is the real issue here.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900