Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用指定的字体名称查找并替换excel中的文本_C#_Excel_Interop - Fatal编程技术网

C# 用指定的字体名称查找并替换excel中的文本

C# 用指定的字体名称查找并替换excel中的文本,c#,excel,interop,C#,Excel,Interop,我正在使用Microsoft Excel 12.0对象库。我的目标是找到具有指定字体名称的文本并替换为新文本 Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); xlApp.FindFormat.Font.Name = "Arial"; workSheet.Cells.Replace('a', 'b', Type.Missing, Type.

我正在使用Microsoft Excel 12.0对象库。我的目标是找到具有指定字体名称的文本并替换为新文本

 Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
 xlApp.FindFormat.Font.Name = "Arial";
 workSheet.Cells.Replace('a', 'b', Type.Missing, Type.Missing, Type.Missing, Type.Missing, xlApp.FindFormat, Type.Missing);
但它不起作用

那么,如何找到具有指定字体名称的字符串并替换为新字符串呢

谢谢大家!

我的c语言不是很流利#下面是vb.net代码:

Imports Microsoft.Office.Interop.Excel
Public Class Class1
Sub TEST()

    Dim xlapp As New Microsoft.Office.Interop.Excel.Application

    xlapp.FindFormat.Font.Name = "Arial"

    Dim wb As Microsoft.Office.Interop.Excel.Workbook

    wb = xlapp.Workbooks.Open("C:\test.xlsx")

    wb.Worksheets("Sheet1").Cells.Replace(What:="*", Replacement:="eee", LookAt:=XlLookAt.xlWhole, _
    SearchOrder:=XlSearchOrder.xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=False)

End Sub
End Class
我运行了一个转换器,它吐出C#:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using Microsoft.Office.Interop.Excel;
public class Class1
{

public void TEST()
{
    Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();

    xlapp.FindFormat.Font.Name = "Arial";

    Microsoft.Office.Interop.Excel.Workbook wb = default(Microsoft.Office.Interop.Excel.Workbook);

    wb = xlapp.Workbooks.Open("C:\\test.xlsx");

    wb.Worksheets("Sheet1").Cells.Replace(What: "*", Replacement: "eee", LookAt: XlLookAt.xlWhole, SearchOrder: XlSearchOrder.xlByRows, MatchCase: false, SearchFormat: true, ReplaceFormat: false);

}
}