I have a spreadsheet that has some conditional formating in some of the cells. I am trying to copy a range that contains these cells to another spreadsheet but the formating is not copying over.
Well, currently it is not available (When you copy a range using Range.Copy() method to somewhere, all the style formattings are copied except the conditional formatting is not attched to the cells.). We will support this feature soon for your need.
Any idea of time frame besides “soon”. Is there any other copy method that would get the conditional cell formats? I tried the row copy but that to does not work
Thanks for your inquiry.
Well, normally, we try our best to fix any issue or add the newer feature ASAP for our clients. If the feature is a small one (after analyzing it), it should take lessor time to make it, sometimes within 3-6 hours you know. And we always try to perform these tasks in parallel with other important tasks which are already described in our planner worklist.
I think currently as a workaround, you may try to extract the conditional formattings attributes from those range of cells and add conditional formattings after you have copied the cells range.
Following is a sample example.
// Create a Workbook object
Workbook workbook = new Workbook();
// Open the Excel file
// Get the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets;
// Create a named range of the Cells
Range range1 = worksheet.Cells.CreateRange("A1", "C9");
// Get the source range of cells...i.e., A21..C29.
Range range2 = worksheet.Cells.CreateRange("A21", "C29");
// Copy the data with formatting of the range to the first range.
ConditionalFormattings cfs = workbook.Worksheets.ConditionalFormattings;
FormatConditions fcs = cfs;
//Get the Font text color.
FormatCondition fc = fcs;
//Get the Formula1
string f1 = fc.Formula1;
OperatorType op1 = fc.Operator;
Color c1 = fc.Style.Font.Color;
int conditionalFormattingIndex = workbook.Worksheets.ConditionalFormattings.Add();
FormatConditions formatConditions = workbook.Worksheets.ConditionalFormattings[conditionalFormattingIndex];
CellArea cellArea = new CellArea();
cellArea.StartColumn = 0;
cellArea.StartRow = 0;
cellArea.EndColumn = 0;
cellArea.EndRow = 8;
int formatConditionIndex = formatConditions.AddCondition(FormatConditionType.CellValue,op1, f1, null);
FormatCondition formatCondition = formatConditions[formatConditionIndex];
formatCondition.Style.Font.Color = c1;
// Save the modified Excel file in default (Excel 2003) format