Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Office2010.Excel - ConditionalFormatting example #1784

Open
gergelyurbancsik opened this issue Sep 6, 2024 · 0 comments
Open

Office2010.Excel - ConditionalFormatting example #1784

gergelyurbancsik opened this issue Sep 6, 2024 · 0 comments

Comments

@gergelyurbancsik
Copy link

gergelyurbancsik commented Sep 6, 2024

Describe the API or scenario A clear and concise description of the scenario you'd like documented: I would like to apply conditional formatting to the 'C' column in an Excel sheet using the ConditionalFormatting class from the DocumentFormat.OpenXml.Office2010.Excel namespace. The conditional formatting should display icons based on the cell values as follows:
• A green check mark for a value of 1
• A red X for values greater than 1
• No icon for a value of 0
Attempts Please include any attempts you have made to figure this out: I have attempted to implement this using the Open-XML-SDK, but I am having trouble with the correct setup of the ConditionalFormatting and ConditionalFormattingRule classes.

Related scenarios Any related documentation/samples/StackOverflow posts you have found: I have not found any specific examples or documentation that cover this exact scenario. Most examples I found are for basic conditional formatting without custom icons.
Additional context Add any other context about the problem here: I am using the Open-XML-SDK to generate Excel files programmatically. Detailed documentation or a sample code snippet demonstrating the correct usage of ConditionalFormatting with custom icons would be very helpful.

the expected result, something like this:

<x14:conditionalFormattings xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main">
		<x14:conditionalFormatting xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">
			<x14:cfRule type="iconSet" priority="1" id="{39D2A77C-A416-446B-91A5-8D3E3C96830E}">
				<x14:iconSet iconSet="3Symbols" showValue="0" custom="1">
					<x14:cfvo type="percent">
						<xm:f>0</xm:f>
					</x14:cfvo>
					<x14:cfvo type="num" gte="0">
						<xm:f>0</xm:f>
					</x14:cfvo>
					<x14:cfvo type="num" gte="0">
						<xm:f>1</xm:f>
					</x14:cfvo>
					<x14:cfIcon iconSet="NoIcons" iconId="0"/>
					<x14:cfIcon iconSet="3Symbols" iconId="2"/>
					<x14:cfIcon iconSet="3Symbols" iconId="0"/>
				</x14:iconSet>
			</x14:cfRule>
			<xm:sqref>C1:C1048576</xm:sqref>
		</x14:conditionalFormatting>
	</x14:conditionalFormattings>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant