Find and replace text in excel with specified font name

后端 未结 1 1985
情歌与酒
情歌与酒 2021-01-13 08:06

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.A         


        
相关标签:
1条回答
  • 2021-01-13 08:45

    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
    

    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);
    
    }
    }
    
    0 讨论(0)
提交回复
热议问题