public void ExcelConditionalFormattingRuleTransformTwoFormulasWithSameAddressInSameXmlConditionalFormattingNode() { FileInfo tempFile = new FileInfo(Path.GetTempFileName()); ExcelAddress originalAddress = new ExcelAddress("C4"); ExcelAddress newAddress = new ExcelAddress("D8"); FileInfo file = new FileInfo(@"MultipleConditionalFormattingAtSameAddress.xlsx"); Assert.IsTrue(file.Exists); using (var package = new ExcelPackage(file)) { var sheet = package.Workbook.Worksheets["Sheet1"]; var conditionalFormattingNodes = sheet.ConditionalFormatting.TopNode.SelectNodes(".//d:conditionalFormatting", sheet.NameSpaceManager); Assert.AreEqual(1, conditionalFormattingNodes.Count); Assert.AreEqual(2, conditionalFormattingNodes.Item(0).ChildNodes.Count); var format1 = sheet.ConditionalFormatting.First(); var format2 = sheet.ConditionalFormatting[1]; Assert.IsTrue(format1 is ExcelConditionalFormattingEqual); Assert.IsTrue(format2 is ExcelConditionalFormattingEqual); Assert.IsTrue(format1 is ExcelConditionalFormattingRule); Assert.IsTrue(format2 is ExcelConditionalFormattingRule); Assert.AreEqual(originalAddress.ToString(), format1.Address.ToString()); Assert.AreEqual(originalAddress.ToString(), format2.Address.ToString()); format1.Address = newAddress; conditionalFormattingNodes = sheet.ConditionalFormatting.TopNode.SelectNodes(".//d:conditionalFormatting", sheet.NameSpaceManager); Assert.AreEqual(2, conditionalFormattingNodes.Count); Assert.AreEqual(1, conditionalFormattingNodes.Item(0).ChildNodes.Count); Assert.AreEqual(1, conditionalFormattingNodes.Item(1).ChildNodes.Count); Assert.IsTrue(format1 is ExcelConditionalFormattingEqual); Assert.IsTrue(format2 is ExcelConditionalFormattingEqual); Assert.IsTrue(format1 is ExcelConditionalFormattingRule); Assert.IsTrue(format2 is ExcelConditionalFormattingRule); Assert.AreEqual(newAddress.ToString(), format1.Address.ToString()); Assert.AreEqual(originalAddress.ToString(), format2.Address.ToString()); format2.Address = newAddress; Assert.AreEqual(2, sheet.ConditionalFormatting.Count); Assert.IsTrue(format1 is ExcelConditionalFormattingEqual); Assert.IsTrue(format2 is ExcelConditionalFormattingEqual); Assert.IsTrue(format1 is ExcelConditionalFormattingRule); Assert.IsTrue(format2 is ExcelConditionalFormattingRule); Assert.AreEqual(newAddress.ToString(), format1.Address.ToString()); Assert.AreEqual(newAddress.ToString(), format2.Address.ToString()); } File.Delete(tempFile.ToString()); }
public int?GetColumn(ExcelAddress address) { string adresa = address.ToString(); char sloupec = adresa.ToCharArray()[0]; int sloupecAscii = int.Parse(((int)sloupec).ToString()) - 64; return(sloupecAscii); }
public int?GetRow(ExcelAddress address) { string adresa = address.ToString(); bool isNumber; if (adresa.Length == 2) { isNumber = int.TryParse(adresa.Substring(1, 1), out int dump); return(isNumber ? dump as int? : null); } else if (adresa.Length == 3) { isNumber = int.TryParse(adresa.Substring(1, 2), out int dump); return(isNumber ? dump as int? : null); } return(null); }