Hi,
I am using the following code to create a sparkline chart, how can I convert it to image? For the common chart object, I can use Aspose.Chart.ToImage method convert the chart to image, is there similar method I can use for sparkline?
Dim ca As New CellArea()
ca.StartColumn = 4
ca.EndColumn = 4
ca.StartRow = 2
ca.EndRow = 2
'Add new Sparklines for a data range to a cell area
Dim idx As Integer ’ = sheet.SparklineGroupCollection.Add(SparklineType.Stacked, “Sheet1!B2:D8”, False, ca)
idx = sheet.SparklineGroupCollection.Add(SparklineType.Column, “Sheet1!C3:D3”, False, ca)
Dim group As SparklineGroup = sheet.SparklineGroupCollection(idx)
'Create CellsColor
Dim clr As CellsColor = book.CreateCellsColor()
clr.Color = Color.Orange
group.SeriesColor = clr
Thanks,
Wei
Hi Wei,
Thanks for your posting and using Aspose.Cells.
You can export range of your cells in a worksheet to image. Please see the following article for your reference.
Please see the source.xlsx file attached with this post. It has a sparkline in cell L5. The following code exported the range L5:L5 to image. I have attached the output image for your reference.
VB.NET
Dim filePath As String = “F:\Shak-Data-RW\Downloads\source.xlsx”
'Create workbook from source file.
Dim m_workbook As Workbook = New Workbook(filePath)
'Access the first worksheet
Dim m_worksheet As Worksheet = m_workbook.Worksheets(0)
'Set the print area with your desired range
m_worksheet.PageSetup.PrintArea = “L5:L5”
'Set all margins as 0
m_worksheet.PageSetup.LeftMargin = 0
m_worksheet.PageSetup.RightMargin = 0
m_worksheet.PageSetup.TopMargin = 0
m_worksheet.PageSetup.BottomMargin = 0
'Set OnePagePerSheet option as true
Dim options As ImageOrPrintOptions = New ImageOrPrintOptions()
options.OnePagePerSheet = True
options.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg
'Take the image of your worksheet
Dim sr As SheetRender = New SheetRender(m_worksheet, options)
sr.ToImage(0, filePath & “.out.jpg”)