无法精确匹配并在Excel中替换 [英] Unable to exact match and replace in excel

查看:153
本文介绍了无法精确匹配并在Excel中替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在将数据从db导出到excel.
我需要对单元格中检索到的数据进行一些更改.
准确地说,我需要将一些字符串替换为其他字符串.

例如在生成的excel中,"ABB"需要替换为"AB".
"MNODays"需要替换为"LM Days"
"MN"需要替换为"LM Hours"

usinf替换功能我尝试了以下操作:

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:

<code><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);





问题是它的精确匹配没有被采用和替换. 如在"MNODays"中一样,将其替换为"LLM Days Hours",并将其与第二个单独的字符串"MN"中的字符混合.

还有其他方法可以实现完全匹配功能吗?
请帮忙

谢谢





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

推荐答案

这都是猜测-)

您确定这就是您所看到的内容吗...即,您从
开始 "MNODays"
并以
结束 法学硕士天数小时"

如果是这样,那么在我看来有些错误了!
我将其分解,然后进行第一次替换,然后查看结果-如果您得到"LMDays",则含义似乎是用值"LMDays"的单元格中的"LM Hours"替换"MN"产生疯狂的"LLM Days Hours".

难道您是不是要说"MNODays"的"MN"位被"LM Hours"代替,而让您留下"LM HoursODays"?

我想您会发现,设置为"Type.Missing"的参数之一可以设置为告诉函数替换整个单元格值,而不是替换任何部分,如果这是真正的问题.
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.


这篇关于无法精确匹配并在Excel中替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆