1

次の Excel VB コードを C# に書き直すのを手伝ってくれませんか?

Range("C9:E11").Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
    Formula1:="=1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
4

2 に答える 2

5

あなたが探しているのは、Excel オートメーションです。これは、Excel が提供する一連の COM オブジェクトを使用して、別のアプリケーションから Excel をリモート コントロールすることを意味します。

VBA でできることはすべて、オートメーションで実現できます (OK、ほとんど何でも)。

「Excel Automation C#」でググるとたくさんヒットします。Microsoft Visual C# .NET から Microsoft Excel を自動化する方法は、最初に返されたもので、開始するのに適した場所のようです。

お役に立てれば、

于 2009-06-15T15:29:59.343 に答える
2
 using Excel = Microsoft.Office.Interop.Excel;
 ...
 object mis = Type.Missing;

 Excel.FormatCondition cond =
    (Excel.FormatCondition)range.FormatConditions.Add(Excel.XlFormatConditionType.xlCellValue,
    Excel.XlFormatConditionOperator.xlEqual, "=1",
    mis, mis, mis, mis, mis);
    cond.Interior.PatternColorIndex = Excel.Constants.xlAutomatic;
    cond.Interior.TintAndShade = 0;
    cond.Interior.Color = ColorTranslator.ToWin32(Color.White);
    cond.StopIfTrue = false;
于 2009-06-16T14:27:38.207 に答える