Copy range with conditional formatting -
i have range conditional formatting in existing excel file. used epplus copy range new sheet, found conditional formatting missing.
is there way copy range conditional formatting using epplus?
i found solution this. did not test on formattingruletypes. (only needed 2 of them moment) in application have 1 template row each sheet.
var formatlist = fromsheet.conditionalformatting.tolist(); foreach (var cf in formatlist) { // sourcerow row containing formatting if (cf.address.start.row == sourcerow ) { iexcelconditionalformattingrule rule = null; switch (cf.type) { case officeopenxml.conditionalformatting.eexcelconditionalformattingruletype.greaterthan: rule = dest.conditionalformatting.addgreaterthan(); break; case officeopenxml.conditionalformatting.eexcelconditionalformattingruletype.greaterthanorequal: rule = dest.conditionalformatting.addgreaterthanorequal(); break; case officeopenxml.conditionalformatting.eexcelconditionalformattingruletype.lessthan: rule = dest.conditionalformatting.addlessthan(); break; case officeopenxml.conditionalformatting.eexcelconditionalformattingruletype.lessthanorequal: rule = dest.conditionalformatting.addlessthanorequal(); break; default: break; } rule.style.fill = cf.style.fill; rule.style.border = cf.style.border; rule.style.font = cf.style.font; rule.style.numberformat = cf.style.numberformat; // have no clue why formula property not included in iexcelconditionalformattingrule interface. needed cast this. ((excelconditionalformattingrule)rule).formula = ((excelconditionalformattingrule)cf).formula; ((excelconditionalformattingrule)rule).formula2 = ((excelconditionalformattingrule)cf).formula2; // calculate new address formatting. different in case var adr = new exceladdress( dest.start.row , cf.address.start.column -1 , dest.start.row, cf.address.start.column -1 + cf.address.columns -1 ); rule.address = adr;
i have no clue why formula property not included in iexcelconditionalformattingrule interface. needed cast this.
Comments
Post a Comment