日期:2014-05-17 浏览次数:21007 次
xSheet.Cells.Replace(what, replace);
/// <summary>
/// 替换excel字符
/// </summary>
/// <param name="strOldText"></param>
/// <param name="strNewText"></param>
public void ExcelReplace( string strOldText, string strNewText)
{
int icount = wb.Sheets.Count;
object what = strOldText; //查找字符串
object retxt = strNewText; //替换字符串
if (xSheet.Cells.Find(strOldText, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
XlSearchDirection.xlNext, Missing.Value, Missing.Value) != null)
{
for (int i = 1; i <= icount; i++)
{
xSheet = (Worksheet)wb.Sheets[i];
}
xSheet.Cells.Replace(what, retxt, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
}
}