2011-06-22 9 views
5

Używam biblioteki obiektów Microsoft Excel 12.0. Moim celem jest znalezienie tekstu o określonej nazwie czcionki i zastąpienie go nowym tekstem.Znajdź i zamień tekst w programie Excel o określonej nazwie czcionki

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); 

ale to nie działa.

Jak znaleźć ciąg znaków o określonej nazwie czcionki i zastąpić go nowym ciągiem?

Dziękujemy!

Odpowiedz

2

że nie jestem biegły w C# Oto kod 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 

wpadłem konwerter który wypluł 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); 

} 
} 
Powiązane problemy