2009-06-09 23 views
4

次のページ:Setting Conditional Formatting in Excel 2007は、私がやりたいこととよく似ていますが、少し違うことをする適切な機能を見つけることができないようです。Excel Interop条件付き書式設定

条件付き書式設定をテキスト値のセットに基づいて範囲に適用する方法を知っている人はいないでしょうか。例えば。

を、あなたが「WARNING」私は無効な値の全範囲を持っている、そしておそらく値を警告YELLOW

を強調表示を見れば「InvalidValue1」OR「InvalidValue2は」他のRED をハイライト表示された場合:私は言いたいです。私はまた、非常に大きなデータセットの列単位でこれを行う必要があります。可能であれば、Excelの組み込み機能を使用して範囲内のエラーを強調したいと考えています。

これはすべて可能なことを知っていますか?

よろしく

答えて

5

セルの選択はかなり奇妙だと私は非常にまだそれを整理していないが、私は(私は問題の解決策を見つけるために管理していると考えている。例えば、私の式は、のために実際にC1を意味A1を使用しています選択された範囲)。ここ

は私が興味を持って誰のために使用されるコードは次のとおり

string condition = @"=OR(ERROR1, ERROR2, ERROR3)"; 
var cfOR = (FormatCondition)targetSheet.get_Range("C1", "C10").FormatConditions.Add(XlFormatConditionType.xlExpression, Type.Missing,condition), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 

cfOR.Interior.Color = 0x000000FF; 
cfOR.Font.Bold = true; 
cfOR.Font.Color = 0x00FFFFFF; 

注FormatConditions.Add()メソッドは、Excelの相互運用の異なるバージョンの異なる署名を有すること。

1

は、.NET 4使用している場合は、以下のダイナミクスと名前付きパラメータ

dynamic range = sheet.Range("A2").Resize(rowCount, 11); 

const string redCondition = "=OR(ERROR1, ERROR2, ERROR3)"; 

dynamic format = range.FormatConditions.Add(XlFormatConditionType.xlExpression, Formula1: redCondition); 
format.Interior.Color = 0x0000FF; 
format.Font.Color = 0x00FFFF; 
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; 
+0

注意を使用して書き直したものです: 'ColorTranslator'は' System.Drawing'を使用する必要があります –