本文介绍了查找并在Excel中与指定的字体名称替换文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Microsoft Excel 12.0对象库。我的目标是找到与文本指定的字体名称和新的文本替换。
I'm using Microsoft Excel 12.0 Object Library. My goal is to find text with specified font name and replace with new text.
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);
但它没有工作。
but it does not works.
因此,如何找到字符串指定的字体名称和新的字符串替换?
So how to find string with specified font name and replace with new string?
感谢您!
推荐答案
我不是说流利的用C#在这里是vb.net代码:
Im not that fluent with c# here is the vb.net code:
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#:
I ran a convertor which spat out 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);
}
}
这篇关于查找并在Excel中与指定的字体名称替换文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!