-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyPictureProvider.vb
42 lines (36 loc) · 1.65 KB
/
MyPictureProvider.vb
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
Imports System
Imports DevExpress.Spreadsheet
Imports System.Collections.Generic
Imports System.Drawing
Imports System.IO
Imports DevExpress.Office.Utils
Namespace SpreadsheetDocumentServerAsDataSourceExample
#Region "#MyPictureProvider"
Public Class MyPictureProvider
Implements IBindingRangeValueConverter
Private pictures As Dictionary(Of String, Bitmap)
Public Sub New(ByVal sheet As Worksheet)
pictures = GetPictures(sheet)
End Sub
Public Function ConvertToObject(ByVal value As CellValue, ByVal requiredType As Type, ByVal columnIndex As Integer) As Object Implements IBindingRangeValueConverter.ConvertToObject
If columnIndex = 13 Then
Dim pic As Bitmap = Nothing
If pictures.TryGetValue(value.TextValue, pic) Then
Return pic
End If
End If
Return value
End Function
Public Function TryConvertFromObject(ByVal value As Object) As CellValue Implements IBindingRangeValueConverter.TryConvertFromObject
Return CellValue.Empty
End Function
Public Function GetPictures(ByVal sheet As Worksheet) As Dictionary(Of String, Bitmap)
Dim employeePictures As Dictionary(Of String, Bitmap) = New Dictionary(Of String, System.Drawing.Bitmap)()
For Each pic As Picture In sheet.Pictures
employeePictures.Add(pic.Name, New Bitmap(New MemoryStream(pic.Image.GetImageBytes(OfficeImageFormat.Bmp))))
Next pic
Return employeePictures
End Function
End Class
#End Region ' #MyPictureProvider
End Namespace