This demo uses the DevExpress Spreadsheet Document API to export document pages to images (BMP, PNG, JPEG, PNG, JPEG, EMF, SVG, and more). You can process the sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.
In the Image Export Settings panel, specify required image settings and select sheets to export. Use the Convert to... dropdown button to select the output format, convert sheets, and download image files.
using DevExpress.Spreadsheet;
using System.Drawing;
IReadOnlyList<Stream> ConvertToImages(Stream inputStream, ImageFileFormat imageFormat, bool exportActiveWorksheetOnly,
int resolution, bool exportGridlines) {
using var workbook = new Workbook();
// Load the input document
workbook.LoadDocument(inputStream);
// Configure image export options
var imageExportOptions = new RangeImageOptions {
Resolution = resolution,
ExportGridlines = exportGridlines,
GridlineColor = Color.Gray,
};
// Get worksheets to export
var worksheetsToExport = new List<Worksheet>();
if(exportActiveWorksheetOnly) {
var activeSheet = workbook.Worksheets.ActiveWorksheet;
worksheetsToExport.Add(activeSheet);
} else
worksheetsToExport = workbook.Worksheets.ToList();
// Export document pages to image streams
var imageStreams = new List<Stream>();
foreach(var worksheet in worksheetsToExport) {
var worksheetImageStream = new MemoryStream();
worksheet.GetUsedRange().ExportToImage(worksheetImageStream, imageFormat, imageExportOptions);
worksheetImageStream.Position = 0;
imageStreams.Add(worksheetImageStream);
}
return imageStreams.AsReadOnly();
}