Skip to content

Conversation

Copy link

Copilot AI commented Sep 22, 2025

This PR adds comprehensive gradient fill support to ImportExcel, addressing the EPPlus 4.x limitation where gradient colors can be set but cannot be read back, preventing gradient copying workflows.

Problem

Users reported (issue #1720) that while gradient colors could be set using EPPlus:

$Sheet.Cells["A1"].Style.Fill.Gradient.Color1.SetColor("BLUE")
$Sheet.Cells["A1"].Style.Fill.Gradient.Color2.SetColor("GREEN")

Reading back the values failed:

$Sheet.Cells["A1"].Style.Fill.Gradient.Color1.Rgb  # Returns empty string

This made it impossible to copy gradients between cells, as the color information was lost.

Solution

Added three new functions that work around EPPlus limitations:

Set-ExcelGradientFill

Clean interface for applying gradient fills with full parameter validation:

Set-ExcelGradientFill -Range $ws.Cells["A1"] -Type Linear -Degree 90 -Color1 Blue -Color2 Green

Get-ExcelGradientFill

Reads gradient properties that can be reliably extracted from EPPlus:

$gradient = Get-ExcelGradientFill -Range $ws.Cells["A1"]
# Returns: Type, Degree, positioning (colors are null with clear explanation)

Copy-ExcelGradientFill

Enables gradient copying via two approaches:

  1. Copy geometric properties only (with warning about colors)
  2. Apply complete gradient definitions including colors
# Complete gradient copying
$gradientDef = @{
    Type = "Linear"
    Degree = 45
    Color1 = [System.Drawing.Color]::Blue
    Color2 = [System.Drawing.Color]::Green
}
Copy-ExcelGradientFill -TargetRange $ws.Cells["B1:D3"] -GradientDefinition $gradientDef

Key Features

  • Comprehensive parameter validation with clear error messages
  • Supports both string color names and Color objects
  • Proper warning messages about EPPlus limitations
  • Full test coverage (13 passing tests)
  • Detailed documentation including migration guide
  • Backwards compatible - no changes to existing functionality

Files Added/Modified

  • Public/Set-ExcelGradientFill.ps1 - New gradient setting function
  • Public/Get-ExcelGradientFill.ps1 - New gradient reading function
  • Public/Copy-ExcelGradientFill.ps1 - New gradient copying function
  • __tests__/GradientFill.tests.ps1 - Comprehensive test suite
  • GRADIENT_GUIDE.md - Detailed usage documentation
  • ImportExcel.psd1 - Updated to export new functions
  • README.md - Added gradient feature documentation

The solution transforms an impossible workflow into a straightforward process while maintaining clear communication about underlying EPPlus limitations.

Fixes #1720.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Author

Copilot AI commented Sep 22, 2025

@dfinke 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Co-authored-by: dfinke <67258+dfinke@users.noreply.github.com>
Copilot AI changed the title [WIP] Issue with Gradients Add gradient fill support to resolve EPPlus color reading limitations Sep 22, 2025
Copilot AI requested a review from dfinke September 22, 2025 11:32
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

Successfully merging this pull request may close these issues.

Issue with Gradients

2 participants