Avatar of deepu Lovelesh
deepu LoveleshFlag for India asked on

graph related problem

i am able to create a chart using excel in vb.net but i need to remove the gridlines from the image being saved. kindly help

Dim xlApp As Microsoft.Office.Interop.Excel.Application

        Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook

        Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet

        Dim misValue As Object = System.Reflection.Missing.Value
        Dim I As Integer = 0
        Dim errMsg As String = ""

        Try
            xlApp = New Microsoft.Office.Interop.Excel.Application

            xlWorkBook = xlApp.Workbooks.Add()

            xlWorkSheet = xlWorkBook.Sheets("Sheet1")



            'add data

            Dim bytes = System.Convert.FromBase64String(strCurveData)

            'STR1 = STR.Split(";")
            For I = 1 To bytes.Count
                xlWorkSheet.Range("A" & I).Value2 = bytes(I - 1)
            Next
            'create chart

            Dim chartPage As Microsoft.Office.Interop.Excel.Chart

            Dim xlCharts As Microsoft.Office.Interop.Excel.ChartObjects

            Dim myChart As Microsoft.Office.Interop.Excel.ChartObject

            Dim chartRange As Microsoft.Office.Interop.Excel.Range



            xlCharts = xlWorkSheet.ChartObjects
            myChart = xlCharts.Add(60, 10, 600, 300)

            chartPage = myChart.Chart

            Dim xlxAxis As Excel.Axis = chartPage.Axes(Excel.XlAxisType.xlCategory)
            'xlxAxis.MajorTickMark = Excel.XlTickMark.xlTickMarkNone
            xlxAxis.HasMajorGridlines = False
            xlxAxis.HasMinorGridlines = False
            'xlxAxis.HasDisplayUnitLabel = False

            chartPage.HasLegend = False
            chartPage.AutoScaling = True
            chartPage.SetBackgroundPicture("D:\Test.jpg")
            'chartPage.ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowNone)

            'chartRange = xlWorkSheet.Range("Sheet1!$1:$1")

            Dim rng = xlWorkSheet.Range("A1:A" & bytes.Count.ToString)

            chartPage.SetSourceData(Source:=rng)


            'chartPage.SetSourceData(Source:=chartRange)

            'chartPage.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlXYScatterSmoothNoMarkers
            chartPage.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlArea

           
            chartPage.ChartWizard(Source:=rng)

            If System.IO.File.Exists(Application.StartupPath & "\" & strCurveName & ".JPG") Then
                System.IO.File.Delete(Application.StartupPath & "\" & strCurveName & ".JPG")
            End If
            chartPage.Export(Application.StartupPath & "\" & strCurveName & ".JPG")

            Dim _fileInfo As New IO.FileInfo(Application.StartupPath & "\" & strCurveName & ".JPG")
            Dim _NumBytes As Long = _fileInfo.Length
            Dim _FStream As New IO.FileStream(Application.StartupPath & "\" & strCurveName & ".JPG", IO.FileMode.Open, IO.FileAccess.Read)
            Dim _BinaryReader As New IO.BinaryReader(_FStream)
            CurveImg = _BinaryReader.ReadBytes(_NumBytes)
            _fileInfo = Nothing
            _NumBytes = 0
            _FStream.Close()
            _FStream.Dispose()
            _BinaryReader.Close()


            '        If System.IO.File.Exists("D:\" & strCurveName & ".JPG") Then
            'System.IO.File.Delete("D:\" & strCurveName & ".JPG")
            'End If


            xlWorkSheet.SaveAs(Application.StartupPath & "\vbexcel.xlsx")

            xlWorkBook.Close()

            xlApp.Quit()
            releaseObject(xlApp)

            releaseObject(xlWorkBook)

            releaseObject(xlWorkSheet)



            If System.IO.File.Exists(Application.StartupPath & "\vbexcel.xlsx") Then
                '    System.IO.File.Delete(Application.StartupPath & "\vbexcel.xlsx")
            End If
            If System.IO.File.Exists(Application.StartupPath & "\" & strCurveName & ".JPG") Then
                '   System.IO.File.Delete(Application.StartupPath & "\" & strCurveName & ".JPG")
            End If

            releaseObject(xlApp)

            releaseObject(xlWorkBook)

            releaseObject(xlWorkSheet)
        Catch ex As Exception
            errMsg = ex.ToString
Visual Basic.NETMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
deepu Lovelesh

8/22/2022 - Mon
Éric Moreau

I don't have the exact code for you but I will give you a trick.

Record a macro in Excel that does exactly what you want to do (remove gridline) and look at the generated code.
Ryan Chong

What's the example value of strCurveData ?
ASKER
deepu Lovelesh

Ryan Chong

You caN USE ANY DATA BUT THE PROBLEM IS TO REMOVE THE GRID LINES FROM THE CHART AS PER THE ABOVE CODE.

THANKS IN ADVANCE
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
deepu Lovelesh

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question