deepu Lovelesh
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.E xcel.Appli cation
Dim xlWorkBook As Microsoft.Office.Interop.E xcel.Workb ook
Dim xlWorkSheet As Microsoft.Office.Interop.E xcel.Works heet
Dim misValue As Object = System.Reflection.Missing. Value
Dim I As Integer = 0
Dim errMsg As String = ""
Try
xlApp = New Microsoft.Office.Interop.E xcel.Appli cation
xlWorkBook = xlApp.Workbooks.Add()
xlWorkSheet = xlWorkBook.Sheets("Sheet1" )
'add data
Dim bytes = System.Convert.FromBase64S tring(strC urveData)
'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.E xcel.Chart
Dim xlCharts As Microsoft.Office.Interop.E xcel.Chart Objects
Dim myChart As Microsoft.Office.Interop.E xcel.Chart Object
Dim chartRange As Microsoft.Office.Interop.E xcel.Range
xlCharts = xlWorkSheet.ChartObjects
myChart = xlCharts.Add(60, 10, 600, 300)
chartPage = myChart.Chart
Dim xlxAxis As Excel.Axis = chartPage.Axes(Excel.XlAxi sType.xlCa tegory)
'xlxAxis.MajorTickMark = Excel.XlTickMark.xlTickMar kNone
xlxAxis.HasMajorGridlines = False
xlxAxis.HasMinorGridlines = False
'xlxAxis.HasDisplayUnitLab el = False
chartPage.HasLegend = False
chartPage.AutoScaling = True
chartPage.SetBackgroundPic ture("D:\T est.jpg")
'chartPage.ApplyDataLabels (Excel.XlD ataLabelsT ype.xlData LabelsShow None)
'chartRange = xlWorkSheet.Range("Sheet1! $1:$1")
Dim rng = xlWorkSheet.Range("A1:A" & bytes.Count.ToString)
chartPage.SetSourceData(So urce:=rng)
'chartPage.SetSourceData(S ource:=cha rtRange)
'chartPage.ChartType = Microsoft.Office.Interop.E xcel.XlCha rtType.xlX YScatterSm oothNoMark ers
chartPage.ChartType = Microsoft.Office.Interop.E xcel.XlCha rtType.xlA rea
chartPage.ChartWizard(Sour ce:=rng)
If System.IO.File.Exists(Appl ication.St artupPath & "\" & strCurveName & ".JPG") Then
System.IO.File.Delete(Appl ication.St artupPath & "\" & strCurveName & ".JPG")
End If
chartPage.Export(Applicati on.Startup Path & "\" & strCurveName & ".JPG")
Dim _fileInfo As New IO.FileInfo(Application.St artupPath & "\" & strCurveName & ".JPG")
Dim _NumBytes As Long = _fileInfo.Length
Dim _FStream As New IO.FileStream(Application. StartupPat h & "\" & strCurveName & ".JPG", IO.FileMode.Open, IO.FileAccess.Read)
Dim _BinaryReader As New IO.BinaryReader(_FStream)
CurveImg = _BinaryReader.ReadBytes(_N umBytes)
_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(Applica tion.Start upPath & "\vbexcel.xlsx")
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
If System.IO.File.Exists(Appl ication.St artupPath & "\vbexcel.xlsx") Then
' System.IO.File.Delete(Appl ication.St artupPath & "\vbexcel.xlsx")
End If
If System.IO.File.Exists(Appl ication.St artupPath & "\" & strCurveName & ".JPG") Then
' System.IO.File.Delete(Appl ication.St artupPath & "\" & strCurveName & ".JPG")
End If
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
Catch ex As Exception
errMsg = ex.ToString
Dim xlApp As Microsoft.Office.Interop.E
Dim xlWorkBook As Microsoft.Office.Interop.E
Dim xlWorkSheet As Microsoft.Office.Interop.E
Dim misValue As Object = System.Reflection.Missing.
Dim I As Integer = 0
Dim errMsg As String = ""
Try
xlApp = New Microsoft.Office.Interop.E
xlWorkBook = xlApp.Workbooks.Add()
xlWorkSheet = xlWorkBook.Sheets("Sheet1"
'add data
Dim bytes = System.Convert.FromBase64S
'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.E
Dim xlCharts As Microsoft.Office.Interop.E
Dim myChart As Microsoft.Office.Interop.E
Dim chartRange As Microsoft.Office.Interop.E
xlCharts = xlWorkSheet.ChartObjects
myChart = xlCharts.Add(60, 10, 600, 300)
chartPage = myChart.Chart
Dim xlxAxis As Excel.Axis = chartPage.Axes(Excel.XlAxi
'xlxAxis.MajorTickMark = Excel.XlTickMark.xlTickMar
xlxAxis.HasMajorGridlines = False
xlxAxis.HasMinorGridlines = False
'xlxAxis.HasDisplayUnitLab
chartPage.HasLegend = False
chartPage.AutoScaling = True
chartPage.SetBackgroundPic
'chartPage.ApplyDataLabels
'chartRange = xlWorkSheet.Range("Sheet1!
Dim rng = xlWorkSheet.Range("A1:A" & bytes.Count.ToString)
chartPage.SetSourceData(So
'chartPage.SetSourceData(S
'chartPage.ChartType = Microsoft.Office.Interop.E
chartPage.ChartType = Microsoft.Office.Interop.E
chartPage.ChartWizard(Sour
If System.IO.File.Exists(Appl
System.IO.File.Delete(Appl
End If
chartPage.Export(Applicati
Dim _fileInfo As New IO.FileInfo(Application.St
Dim _NumBytes As Long = _fileInfo.Length
Dim _FStream As New IO.FileStream(Application.
Dim _BinaryReader As New IO.BinaryReader(_FStream)
CurveImg = _BinaryReader.ReadBytes(_N
_fileInfo = Nothing
_NumBytes = 0
_FStream.Close()
_FStream.Dispose()
_BinaryReader.Close()
' If System.IO.File.Exists("D:\
'System.IO.File.Delete("D:
'End If
xlWorkSheet.SaveAs(Applica
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
If System.IO.File.Exists(Appl
' System.IO.File.Delete(Appl
End If
If System.IO.File.Exists(Appl
' System.IO.File.Delete(Appl
End If
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
Catch ex As Exception
errMsg = ex.ToString
What's the example value of strCurveData ?
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi deepu Lovelesh ,
How you done this ?., I am also not able to remove background.
Can you help me over here . I m also need to draw chart from the histogram string. So let me know how you have done this.
Record a macro in Excel that does exactly what you want to do (remove gridline) and look at the generated code.