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

Set charts background and add text wrap to box shapes #1786

Closed
LaneDoesData opened this issue Jan 19, 2024 · 1 comment · Fixed by #1788
Closed

Set charts background and add text wrap to box shapes #1786

LaneDoesData opened this issue Jan 19, 2024 · 1 comment · Fixed by #1788
Labels
enhancement New feature or request

Comments

@LaneDoesData
Copy link

I believe that you can edit the xml files associated with the Excel file (this is not a stable solution) but is it possible to add a feature to

  1. set the background color of charts (to transparent or another color)
  2. add text wrapping to box shapes
@xuri xuri added enhancement New feature or request in progress Working in progress labels Jan 21, 2024
melf-xyzh added a commit to melf-xyzh/excelize that referenced this issue Jan 21, 2024
xuri pushed a commit that referenced this issue Jan 22, 2024
- Add a new field Fill in Chart, ChartPlotArea, and ChartMarker struct
- Support set solid color or transparent fill for chart area, plot area, and maker
@xuri
Copy link
Member

xuri commented Jan 22, 2024

Thanks for your issue.

  1. We have added a new field Fill in Chart, ChartPlotArea, and ChartMarker struct, for support set solid color or transparent fill for chart area, plot area, and maker. Please try to upgrade the master branch code, and this feature will be released in the next version.
  2. This library already support add text wrap to box shapes.

For example:

package main

import (
    "fmt"

    "github.com/xuri/excelize/v2"
)

func main() {
    f := excelize.NewFile()
    defer func() {
        if err := f.Close(); err != nil {
            fmt.Println(err)
        }
    }()
    for idx, row := range [][]interface{}{
        {nil, "Apple", "Orange", "Pear"}, {"Small", 2, 3, 3},
        {"Normal", 5, 2, 4}, {"Large", 6, 7, 8},
    } {
        cell, err := excelize.CoordinatesToCellName(1, idx+1)
        if err != nil {
            fmt.Println(err)
            return
        }
        f.SetSheetRow("Sheet1", cell, &row)
    }
    if err := f.AddChart("Sheet1", "E1", &excelize.Chart{
        Type: excelize.Line,
        Series: []excelize.ChartSeries{
            {
                Name:       "Sheet1!$A$2",
                Categories: "Sheet1!$B$1:$D$1",
                Values:     "Sheet1!$B$2:$D$2",
            },
            {
                Name:       "Sheet1!$A$3",
                Categories: "Sheet1!$B$1:$D$1",
                Values:     "Sheet1!$B$3:$D$3",
            },
            {
                Name:       "Sheet1!$A$4",
                Categories: "Sheet1!$B$1:$D$1",
                Values:     "Sheet1!$B$4:$D$4",
                Marker: excelize.ChartMarker{
                    // Specify solid fill for chart marker by Fill field
                    Fill: excelize.Fill{Type: "pattern", Color: []string{"777777"}, Pattern: 1},
                },
            }},
        Title: []excelize.RichTextRun{
            {
                Text: "Line Chart",
            },
        },
        // Specify transparent fill for chart area by Fill field,
        // declare Type and Pattern, but without Color
        Fill: excelize.Fill{Type: "pattern", Pattern: 1},
        PlotArea: excelize.ChartPlotArea{
            // Specify transparent fill for chart plot area by Fill field,
            // declare Type and Pattern, but without Color
            Fill: excelize.Fill{Type: "pattern", Pattern: 1},
        },
    }); err != nil {
        fmt.Println(err)
        return
    }

    // Add a rectangle shape with gray fill color and rich-text
    if err := f.AddShape("Sheet1", &excelize.Shape{
        Cell: "B7",
        Type: "rect",
        Paragraph: []excelize.RichTextRun{
            {Text: "Rectangle", Font: &excelize.Font{Color: "CD5C5C"}},
            {Text: "Shape", Font: &excelize.Font{Bold: true, Color: "2980B9"}},
        },
        Fill:   excelize.Fill{Type: "pattern", Color: []string{"DDDDDD"}, Pattern: 1},
        Height: 50,
        Width:  80,
    }); err != nil {
        fmt.Println(err)
        return
    }

    // Save spreadsheet by the given path.
    if err := f.SaveAs("Book1.xlsx"); err != nil {
        fmt.Println(err)
    }
}

@xuri xuri removed the in progress Working in progress label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants