-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyPictureProvider.cs
47 lines (42 loc) · 1.37 KB
/
MyPictureProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using DevExpress.Spreadsheet;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using DevExpress.Office.Utils;
namespace SpreadsheetDocumentServerAsDataSourceExample
{
#region #MyPictureProvider
public class MyPictureProvider : IBindingRangeValueConverter
{
Dictionary<string, Bitmap> pictures;
public MyPictureProvider(Worksheet sheet)
{
pictures = GetPictures(sheet);
}
public object ConvertToObject(CellValue value, Type requiredType, int columnIndex)
{
if (columnIndex == 13)
{
Bitmap pic;
if (pictures.TryGetValue(value.TextValue, out pic))
return pic;
}
return value;
}
public CellValue TryConvertFromObject(object value)
{
return CellValue.Empty;
}
public Dictionary<string, Bitmap> GetPictures(Worksheet sheet)
{
Dictionary<string, Bitmap> employeePictures = new Dictionary<string, System.Drawing.Bitmap>();
foreach (Picture pic in sheet.Pictures)
{
employeePictures.Add(pic.Name, new Bitmap(new MemoryStream(pic.Image.GetImageBytes(OfficeImageFormat.Bmp))));
}
return employeePictures;
}
}
#endregion #MyPictureProvider
}