-
Notifications
You must be signed in to change notification settings - Fork 41
Added new kb article export-charts-png-300dpi-spreadprocessing #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
title: Exporting Charts from Excel Documents to PNG Images with a Specific DPI Resolution Using SpreadProcessing | ||
description: Learn how to export Excel charts to PNG images with a Specific DPI resolution using Telerik SpreadProcessing and charting controls. | ||
type: how-to | ||
page_title: Exporting Charts from Excel Documents to PNG Images with a Specific DPI Resolution Using SpreadProcessing | ||
meta_title: Exporting Charts from Excel Documents to PNG Images with a Specific DPI Resolution Using SpreadProcessing | ||
slug: export-charts-png-300dpi-spreadprocessing | ||
tags: spread, processing,telerik, document ,chart, image, export, png, dpi, resolution | ||
res_type: kb | ||
ticketid: 1695547 | ||
--- | ||
|
||
## Environment | ||
|
||
| Version | Product | Author | | ||
| ---- | ---- | ---- | | ||
| 2025.2.520| RadSpreadProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| | ||
|
||
## Description | ||
|
||
Learn how to extract the [charts]({%slug radspreadprocessing-features-charts%}) from Excel documents and save as PNG files specifying the desired resolution, e.g. 300 DPI. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edit: Learn how to extract the [charts]({%slug radspreadprocessing-features-charts%}) from Excel documents and save them as PNG files, while specifying the desired resolution (e.g. 300 DPI). |
||
|
||
## Solution | ||
|
||
Exporting charts directly from Excel files to PNG images with a specific resolution (e.g.300 DPI) using Telerik [SpreadProcessing]({%slug radspreadprocessing-overview%}) is not supported. SpreadProcessing focuses on spreadsheet data manipulation and exporting to formats like XLSX and PDF but does not handle chart export or DPI settings. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole paragraph is irrelevant and can be trimmed, as it focuses on what the library cannot do. Consider adding a description of the actual approch that needs to be taken. For example: Exporting Charts from Excel files to images is not yet supported by the SpreadProcessing library. As an alternative... |
||
|
||
### Suggested Workflow Using Charting Controls | ||
|
||
1. Extract the chart data from the Excel file using SpreadProcessing. | ||
2. Rebuild the chart using a UI component, such as [RadChartView](https://docs.telerik.com/devtools/winforms/controls/chartview/features/export) from the Telerik UI for WinForms or WPF suites. | ||
3. Export the chart as a PNG image with 300 DPI using RadChartView. | ||
|
||
### Alternative Approach: Exporting to PDF | ||
|
||
Export the XLSX document to PDF format using SpreadProcessing. This method internally uses a **chart renderer** for rendering charts in the PDF. Implement a custom [IPdfChartRenderer]({%slug radspreadprocessing-features-charts-pdf-export%}) to manipulate chart resolution and save the chart as a PNG image in the ongoing export process. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add code snippet for this approach as well. |
||
|
||
#### Sample implementation for exporting charts as PNG with 300 DPI: | ||
|
||
```csharp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code snippet is incomplete. There is no import of document, extracting the chartShape, and creating a FixedContentEditor. Consider expanding the snippet so it is buildable once pasted in a project. |
||
public class WinFormsPdfChartImageRenderer : IPdfChartRenderer | ||
{ | ||
public void RenderChart(FixedContentEditor editor, FloatingChartShape chartShape) | ||
{ | ||
string filePath = @"exportedChart.png"; | ||
|
||
// Set chart dimensions | ||
System.Drawing.Size size = new System.Drawing.Size((int)(chartShape.Width), (int)(chartShape.Height + 10)); | ||
System.Drawing.Image chartImage = Telerik.WinForms.Controls.Spreadsheet.Layers.ChartModelToImageConverter.GetImageFromFloatingChartShape(chartShape, size); | ||
|
||
using (var bmp = new Bitmap(chartImage)) | ||
{ | ||
// Set DPI to 300 | ||
bmp.SetResolution(300, 300); | ||
|
||
// Save as PNG | ||
bmp.Save(filePath, System.Drawing.Imaging.ImageFormat.Png); | ||
} | ||
using (FileStream fs = new FileStream(filePath, FileMode.Open)) | ||
{ | ||
editor.DrawImage(fs); | ||
} | ||
Process.Start(new ProcessStartInfo(filePath) { UseShellExecute = true }); | ||
} | ||
} | ||
``` | ||
|
||
To export charts to PNG, use the custom renderer in conjunction with SpreadProcessing’s PDF export functionalities. Charts saved as PNG images can then be adjusted for resolution. | ||
|
||
Note: Recreating the chart using RadChartView may require extra effort if the charts are highly customized or complex. | ||
|
||
## See Also | ||
|
||
- [SpreadProcessing PDF Export]({%slug radspreadprocessing-features-charts-pdf-export%}) | ||
- [Exporting Spreadsheets with Charts to PDF with RadSpreadProcessing and WinForms RadChartView]({%slug export-charts-to-pdf-radspreadprocessing%}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider rephrasing the titles and descriptions to include the use of the UI for WinForms and WPF suites, as well as the PdfProcessing library. Currently, only the SpreadProcessing library is mentioned.