How to add to Text Box For excel Charts RRS feed

  • General discussion

  • Hello Msdns

    I dont know why this one is not one able to solve it i have posted couple of time in various blog

    Currently i have requirement need to have label  in Excel charts 

    Please let me know how to do this , 

    I am dont want use in interoperatiblity because of performance issue ,

    please guide how to do in Open excel or EEPLUS any XLSX version 


    1000 thanks return


    Ranjith@Learner @Microsoft products

    Ranjith@Learner @Microsoft products

    Thursday, May 19, 2016 8:43 PM

All replies

  • I'm only familiar with VBA, so I don't know what you mean by "Open excel or EEPLUS any XLSX version".  In VBA, you can use the Add method of the TextBoxes object.  Hopefully this will get you started...

    Option Explicit
    Sub AddTextBoxToChart()
        Dim myTextBox As TextBox
        Dim TextBoxWidth As Integer
        Dim TextBoxHeight As Integer
        Dim TopPos As Double
        Dim LeftPos As Double
        If ActiveChart Is Nothing Then
            MsgBox "Select a chart, and try again.", vbExclamation
            Exit Sub
        End If
        TextBoxWidth = 100
        TextBoxHeight = 20
        With ActiveChart
            With .ChartArea
                LeftPos = .Width - TextBoxWidth
                TopPos = .Height - TextBoxHeight
            End With
            Set myTextBox = .TextBoxes.Add(LeftPos, TopPos, TextBoxWidth, TextBoxHeight)
            With myTextBox
                .Font.Name = "Arial"
                .Font.Size = 8
                .Text = "Add some text here"
            End With
        End With
    End Sub

    Hope this helps!

    Domenic Tamburino Microsoft MVP - Excel xl-central.com - "For Your Microsoft Excel Solutions"

    Friday, May 20, 2016 12:02 AM
  • If you want to add textbox to chart using C#, try this: http://freenetexcel.codeplex.com

    //Load Workbook Workbook workbook = new Workbook(); workbook.LoadFromFile("Sale.xlsx"); Worksheet sheet = workbook.Worksheets[0]; //Add Chart and Set Chart Data Range Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered); chart.DataRange = sheet.Range["D1:G3"]; chart.SeriesDataFromRange = false; //Chart Position chart.LeftColumn = 1; chart.TopRow = 5; chart.RightColumn = 8; chart.BottomRow = 23; //Chart Border chart.ChartArea.Border.Weight = ChartLineWeightType.Medium; chart.ChartArea.Border.Color = Color.SandyBrown; //Chart Title chart.ChartTitle = "Parts Sales Info"; chart.ChartTitleArea.Font.FontName = "Calibri"; chart.ChartTitleArea.Font.Size = 13; chart.ChartTitleArea.Font.IsBold = true; //Chart Axis chart.PrimaryCategoryAxis.Title = "Parts"; chart.PrimaryCategoryAxis.Font.Color = Color.Blue; chart.PrimaryValueAxis.Title = "Amounts"; chart.PrimaryValueAxis.HasMajorGridLines = false; chart.PrimaryValueAxis.MaxValue = 200; chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90; //Chart Legend chart.Legend.Position = LegendPositionType.Right;

    //Add Textbox without Borderline XlsTextBoxShape textbox = chart.TextBoxes.AddTextBox(900, 800, 80, 200) as XlsTextBoxShape; textbox.Text = "Some Text"; textbox.Line.Weight = 0; workbook.SaveToFile("AddTextboxToChart.xlsx");

    Friday, May 20, 2016 2:12 AM
  • actually its not free so i cant use that please let me know any alternative way 

    Ranjith@Learner @Microsoft products

    Friday, May 20, 2016 7:27 AM
  • please help him write a VBscript which executes when your opens add txt box to all charts present in all worksheet 

    Ranjith@Learner @Microsoft products

    Friday, May 20, 2016 7:31 AM