troubleshooting Question

graph related problem

Avatar of deepu Lovelesh
deepu LoveleshFlag for India asked on
Microsoft OfficeMicrosoft ExcelVisual Basic.NET
4 Comments1 Solution39 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
deepu Lovelesh

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros