We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Conditional Formattings not providing the Range

hey,

I tried to get the Conditional formatting of a worksheet(s),
I am able to get it but not able to ge the Cell Ranges that are having the Conditional Formatting.

I am using the following code.
Private Sub GetCellConditionalFormatting(ByRef pobjWS As Aspose.Cells.Worksheet)
Dim objConditionCollection As Aspose.Cells.FormatConditionCollection = Nothing
Dim objFormatCondition As Aspose.Cells.FormatCondition = Nothing
Dim strCellAddress As String = String.Empty
Dim strWSName As String = String.Empty
Dim strDetails As String = String.Empty
Try
strWSName = pobjWS.Name & “”
For Each objConditionCollection In pobjWS.ConditionalFormattings
If Not IsNothing(objConditionCollection) Then
For intIndex As Integer = 0 To objConditionCollection.Count - 1
objFormatCondition = objConditionCollection.Item(intIndex)
If Not IsNothing(objFormatCondition) Then
strDetails = strWSName & " " & objFormatCondition.Type.ToString & " " & objFormatCondition.Operator.ToString & " " & objFormatCondition.Formula1.ToString & " " & objFormatCondition.Formula2.ToString & vbNewLine
End If
Next
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

By using this code i am not able to get the Cell Addresses or range on which the conditional formatting is having.

@harshCIPL22,
Could you please share your template file with bit more details and screenshots of your requirements in MS Excel. We will provide our feedback after analysis.

I am attaching a file and 2 screenshots.
In the image “(Output.png)” you can see that I am getting the All details except the Cell Range or Cells that ar actually being format.
In the Image "(CD_ws.png) " I highlighted the Cells or Range that are having Conditional Formatting.
For more details, I am using the same code that I posted in previous blog.

Conditional Formatting.zip (35.5 KB)

I need the Cell Addresses or Range that are being format using Conditional Format With All that details.

@harshCIPL22,
You may please give a try to the following sample code and share the feedback. It displays the cell area along with other information.

Workbook workbook = new Workbook(basePath + "Cells_208547\\asp.xls");
Worksheet pobjWS = workbook.Worksheets[0];

foreach (FormatConditionCollection conditionalFormatting in pobjWS.ConditionalFormattings)
{
    for(int i = 0; i < conditionalFormatting.Count; i++)
    {
        FormatCondition formatCondition = conditionalFormatting[i] as FormatCondition;
        CellArea cellsArea = conditionalFormatting.GetCellArea(i);
        Console.WriteLine($@"Type={formatCondition.Type},Operator = {formatCondition.Operator},Formula1 = {formatCondition.Formula1},Formula2 = {formatCondition.Formula2}, StartRow = {cellsArea.StartRow}, EndRow = {cellsArea.EndRow}, StartColumn = {cellsArea.StartColumn},EndColumn = {cellsArea.EndColumn}");
    }
}

Thanks for the help,
I was not aware about the property.
It solved my problem.

Once again thanks for the help.

@harshCIPL22,

Good to know that your issue is sorted out by the suggested code segment. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.