facebooktwittermenuarrow-up

GemBox Support Forum

Copy the content of cell as an Image/Bitmap

Hi All,
I have a current Excel sheet with one column filled with specific font text.
I have to distribute this excel spreadsheet to an audience that doesn’t have the used font.
Directly in Excel, this is possible to Copy a cell and “Paste as Image” the content of the cell.
Do we have anything similar using GemBox ?
Thanks in advance
DR

Hi,

Would the following code work for you?

var ef = new ExcelFile();

var ws = ef.Worksheets.Add("Sheet1");

ws.Cells["A1"].Value = "A1 value";
ws.Cells["A2"].Value = "A2 value";
ws.Cells["A3"].Value = "A3 value";
ws.Cells["A4"].Value = "A4 value";

// Only cells A2 to A3 should be exported to an image.
ws.NamedRanges.SetPrintArea(ws.Cells.GetSubrange("A2", "A3"));
var imageStream = new MemoryStream();
ef.Save(imageStream, new ImageSaveOptions(ImageSaveFormat.Png) { CropToContent = true });
// Reset print area.
ws.NamedRanges.SetPrintArea((CellRange)null);

ws.Pictures.Add(imageStream, ExcelPictureFormat.Png, "C2", "C3");

var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
ef.Save(Path.Combine(desktop, "PasteAsImage.xlsx"));
1 Like

Hi,
This is exactly what I need.
Thanks for that answer…
Just perfect !!