本帖最后由 cccc 于 2024-8-1 13:58 编辑
替换自定义函数
public void ReplaceStr_GC(GrapeCity.Documents.Excel.IRange range_Ref, string strFind, string strRepl, int iLookAt = 2)
{
try
{
ReplaceOptions replaceOptions = new ReplaceOptions();
if (iLookAt == 2)
{ replaceOptions.LookAt = LookAt.Part; }
else
{ replaceOptions.LookAt = LookAt.Whole; }
replaceOptions.MatchByte = false;
replaceOptions.MatchCase = false;
range_Ref.Replace(strFind, strRepl, replaceOptions);//替换
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
调用替换自定义函数,替换含有"*"的字符串
GrapeCity.Documents.Excel.IRange rangetest = rng1.Columns[2];
ReplaceStr_GC(rangetest, "*", "");
或 ReplaceStr_GC(rangetest, "~*~", "");
都会报“不支持通配符”的错误。要如何修改,gcexcel可以实现对区域带*的字符串替换成空。
|
|