-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDocumentPropertiesActions.vb
95 lines (88 loc) · 4.57 KB
/
DocumentPropertiesActions.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Imports DevExpress.Spreadsheet
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Namespace SpreadsheetExamples
Friend Class DocumentPropertiesActions
#Region "DocumentProperties"
Public Shared BuiltInPropertiesAction As Action(Of IWorkbook) = AddressOf BuiltInPropertiesValue
Public Shared CustomPropertiesAction As Action(Of IWorkbook) = AddressOf CustomPropertiesValue
#End Region
Private Shared Sub BuiltInPropertiesValue(ByVal workbook As IWorkbook)
workbook.BeginUpdate()
Try
Dim worksheet As Worksheet = workbook.Worksheets(0)
worksheet.Columns(0).WidthInCharacters = 2
worksheet("E6").Value = "Mike Hamilton"
Dim header As CellRange = worksheet.Range("B2:C2")
header(0).Value = "Property Name"
header(1).Value = "Value"
header.Style = workbook.Styles(BuiltInStyleId.Accent2)
#Region "#Built-inProperties"
' Set the built-in document properties.
workbook.DocumentProperties.Title = "Spreadsheet API: document properties example"
workbook.DocumentProperties.Description = "How to manage document properties using the Spreadsheet API"
workbook.DocumentProperties.Keywords = "Spreadsheet, API, properties, OLEProps"
workbook.DocumentProperties.Company = "Developer Express Inc."
' Display the specified built-in properties in a worksheet.
worksheet("B3").Value = "Title"
worksheet("C3").Value = workbook.DocumentProperties.Title
worksheet("B4").Value = "Description"
worksheet("C4").Value = workbook.DocumentProperties.Description
worksheet("B5").Value = "Keywords"
worksheet("C5").Value = workbook.DocumentProperties.Keywords
worksheet("B6").Value = "Company"
worksheet("C6").Value = workbook.DocumentProperties.Company
#End Region ' #Built-inProperties
worksheet.Columns.AutoFit(1, 2)
Finally
workbook.EndUpdate()
End Try
End Sub
Private Shared Sub CustomPropertiesValue(ByVal workbook As IWorkbook)
workbook.BeginUpdate()
Try
Dim worksheet As Worksheet = workbook.Worksheets(0)
worksheet.Columns(0).WidthInCharacters = 2
Dim header As CellRange = worksheet.Range("B2:C2")
header(0).Value = "Property Name"
header(1).Value = "Value"
header.Style = workbook.Styles(BuiltInStyleId.Accent2)
header.ColumnWidthInCharacters = 20
#Region "#CustomProperties"
' Set the custom document properties.
workbook.DocumentProperties.Custom("Revision") = 3
workbook.DocumentProperties.Custom("Completed") = True
workbook.DocumentProperties.Custom("Published") = Date.Now
#End Region ' #CustomProperties
#Region "#LinkToContent"
' Define a name to the cell linked to the custom property.
workbook.DefinedNames.Add("checked_by", "E6")
' Connect the custom property with the named cell.
workbook.DocumentProperties.Custom.LinkToContent("Checked by", "checked_by")
#End Region ' #LinkToContent
#Region "#DisplayCustomProperties"
' Display the specified custom properties in a worksheet.
Dim customPropertiesNames As IEnumerable(Of String) = workbook.DocumentProperties.Custom.Names
Dim rowIndex As Integer = 2
For Each propertyName As String In customPropertiesNames
worksheet(rowIndex, 1).Value = propertyName
worksheet(rowIndex, 2).Value = workbook.DocumentProperties.Custom(propertyName)
If worksheet(rowIndex, 2).Value.IsDateTime Then worksheet(rowIndex, 2).NumberFormat = "[$-409]m/d/yyyy h:mm AM/PM"
rowIndex += 1
Next
#End Region ' #DisplayCustomProperties
#Region "#RemoveCustomProperty"
' Remove an individual custom document property.
workbook.DocumentProperties.Custom("Published") = Nothing
#End Region ' #RemoveCustomProperty
#Region "#ClearCustomProperties"
' Remove all custom document properties.
#End Region ' #ClearCustomProperties
workbook.DocumentProperties.Custom.Clear()
Finally
workbook.EndUpdate()
End Try
End Sub
End Class
End Namespace