日期:2014-05-17 浏览次数:20845 次
class wo
{
public wo(string Excelpath)
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
excel.Visible = false;
Workbook wb = excel.Workbooks._Open(Excelpath,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
}
public void ExcelReplace(string strOldText, string strNewText)
{
int icount = wb.Sheets.Count;
for (int i = 1; i <= icount; i++)
{
xSheet = (Worksheet)wb.Sheets[i];
object what = strOldText; //查找字符串
object retxt = strNewText; //替换字符串
xSheet.Cells.Replace(what, retxt, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
wo w = new wo(@"C:\Documents and Settings\Administrator\桌面\Sheet1.xls");
w.ExcelReplace("object1.Tittle", "qq");
}