|
1 | 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
2 | 2 | using OfficeOpenXml; |
3 | 3 | using OfficeOpenXml.ConditionalFormatting; |
| 4 | +using OfficeOpenXml.ConditionalFormatting.Contracts; |
4 | 5 | using OfficeOpenXml.Style; |
| 6 | +using System.Drawing; |
5 | 7 | using System.Globalization; |
6 | 8 | using System.Threading; |
7 | 9 |
|
@@ -75,5 +77,89 @@ public void Test1_Input_ExpectedOutput() |
75 | 77 | SaveAndCleanup(package); |
76 | 78 | Thread.CurrentThread.CurrentCulture = currentCulture; |
77 | 79 | } |
| 80 | + |
| 81 | + [TestMethod] |
| 82 | + public void s1025() |
| 83 | + { |
| 84 | + using (var package = OpenTemplatePackage("s1025.xlsx")) |
| 85 | + { |
| 86 | + ExcelWorkbook wb = package.Workbook; |
| 87 | + ExcelWorksheet ws = wb.Worksheets[0]; |
| 88 | + |
| 89 | + IExcelConditionalFormattingBetween condGreen = ws.ConditionalFormatting.AddBetween(ws.Cells[5, 2, 25, 2]); |
| 90 | + condGreen.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; |
| 91 | + condGreen.Style.Fill.BackgroundColor.Color = ColorTranslator.FromHtml("#A9D08E"); |
| 92 | + condGreen.Formula = ws.Cells[6, 7].FullAddressAbsolute.ToString(); |
| 93 | + condGreen.Formula2 = ws.Cells[6, 8].FullAddressAbsolute.ToString(); |
| 94 | + |
| 95 | + IExcelConditionalFormattingBetween condYellow = ws.ConditionalFormatting.AddBetween(ws.Cells[5, 2, 25, 2]); |
| 96 | + condYellow.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; |
| 97 | + condYellow.Style.Fill.BackgroundColor.Color = ColorTranslator.FromHtml("#FFE699"); |
| 98 | + condYellow.Formula = ws.Cells[7, 7].FullAddressAbsolute.ToString(); |
| 99 | + condYellow.Formula2 = ws.Cells[7, 8].FullAddressAbsolute.ToString(); |
| 100 | + |
| 101 | + IExcelConditionalFormattingGreaterThan condRed = ws.ConditionalFormatting.AddGreaterThan(ws.Cells[5, 2, 25, 2]); |
| 102 | + condRed.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; |
| 103 | + condRed.Style.Fill.BackgroundColor.Color = ColorTranslator.FromHtml("#FF7979"); |
| 104 | + condRed.Formula = ws.Cells[9, 7].FullAddressAbsolute.ToString(); |
| 105 | + |
| 106 | + Assert.AreEqual(6, condRed.Priority); |
| 107 | + |
| 108 | + SaveAndCleanup(package); |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + [TestMethod] |
| 113 | + public void VerifyReadWritePriority() |
| 114 | + { |
| 115 | + using (var p = OpenPackage("CFReadWritePriority.xlsx", true)) |
| 116 | + { |
| 117 | + var ws = p.Workbook.Worksheets.Add("CFReadWritePriorityWs"); |
| 118 | + |
| 119 | + ws.Cells["A1:C10"].Formula = "ROW()+COLUMN()"; |
| 120 | + |
| 121 | + ws.Calculate(); |
| 122 | + |
| 123 | + var cf1 = ws.Cells["A1:A10"].ConditionalFormatting.AddAboveAverage(); |
| 124 | + var cf2 = ws.Cells["A1:A10"].ConditionalFormatting.AddAboveAverage(); |
| 125 | + |
| 126 | + cf1.Style.Fill.BackgroundColor.SetColor(Color.RosyBrown); |
| 127 | + |
| 128 | + cf2.Style.Fill.BackgroundColor.SetColor(Color.DarkGreen); |
| 129 | + |
| 130 | + var cfB1 = ws.Cells["B1:B10"].ConditionalFormatting.AddBetween(); |
| 131 | + cfB1.Formula = "4"; |
| 132 | + cfB1.Formula2 = "14"; |
| 133 | + |
| 134 | + var cfB2 = ws.Cells["B1:B10"].ConditionalFormatting.AddBetween(); |
| 135 | + |
| 136 | + cfB2.Formula = "14"; |
| 137 | + cfB2.Formula2 = "35"; |
| 138 | + |
| 139 | + cfB1.Style.Fill.BackgroundColor.SetColor(Color.BlueViolet); |
| 140 | + cfB2.Style.Fill.BackgroundColor.SetColor(Color.Chartreuse); |
| 141 | + |
| 142 | + cfB1.Priority = 1; |
| 143 | + |
| 144 | + SaveAndCleanup(p); |
| 145 | + } |
| 146 | + |
| 147 | + using (var p = OpenPackage("CFReadWritePriority.xlsx", false)) |
| 148 | + { |
| 149 | + var ws = p.Workbook.Worksheets[0]; |
| 150 | + |
| 151 | + var cfText = ws.Cells["C3:C5"].ConditionalFormatting.AddContainsText(); |
| 152 | + |
| 153 | + cfText.Formula = ""; |
| 154 | + cfText.Style.Fill.BackgroundColor.Color = Color.Red; |
| 155 | + |
| 156 | + Assert.AreEqual(5, cfText.Priority); |
| 157 | + |
| 158 | + var outFile = GetOutputFile("", "CFSamePriorityResave.xlsx"); |
| 159 | + |
| 160 | + p.SaveAs(outFile); |
| 161 | + //SaveAndCleanup(p); |
| 162 | + } |
| 163 | + } |
78 | 164 | } |
79 | 165 | } |
0 commit comments