如何导出图片到Excel
问题描述:如何向Spread 中添加图片,并且导出到Excel 中。问题解答:通过ImageCellType 添加图片到单元格后,使用SaveExcel保存为Excel即可。
关键代码:
private void AddImageToCell()
{
FarPoint.Win.Spread.CellType.ImageCellType icelltype = new FarPoint.Win.Spread.CellType.ImageCellType();
icelltype.Style = FarPoint.Win.RenderStyle.Stretch;
icelltype.TransparencyColor = Color.Black;
icelltype.TransparencyTolerance = 100;
fpSpread1.Sheets.Rows.CellType = icelltype;
System.Drawing.Image image = (System.Drawing.Image)Properties.Resources.ResourceManager.GetObject("Tulips");
System.IO.MemoryStream stream = new System.IO.MemoryStream();
byte[] bytes;
string str;
image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
stream.Seek(0, System.IO.SeekOrigin.Begin);
bytes = stream.GetBuffer();
str = System.Convert.ToBase64String(bytes);
fpSpread1.Sheets.Cells.Value = image;
fpSpread1.Sheets.Cells.Text = "test";
fpSpread1.Sheets.Protect = false;
this.fpSpread1.SaveExcel("test.xls");
}
效果截图:
示例下载:点击下载
页:
[1]