我正在尝试在 RESTful API中为Private Sub btnGenerateEmail_Click()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim nRow As Integer
Dim tblEmailTo As ListObject
Dim tblEmailCC As ListObject
Dim sToEmail As String
Dim sCCEmail As String
Dim sSalutation As String
Dim dteEffectiveDate As Date
Dim sSignature As String
On Error GoTo EH
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
Set tblEmailTo = ThisWorkbook.Sheets("Ref").ListObjects("TblEmailTo")
Set tblEmailCC = ThisWorkbook.Sheets("Ref").ListObjects("TblEmailCC")
For nRow = 1 To tblEmailTo.ListRows.Count
sToEmail = sToEmail & tblEmailTo.DataBodyRange(nRow, 1).Value & "; "
Next nRow
If tblEmailTo.ListRows.Count = 1 Then
sSalutation = "Hi " & Mid(sToEmail, 1, InStr(1, sToEmail, ".") - 1) & ","
Else
sSalutation = "Hi All,"
End If
For nRow = 1 To tblEmailCC.ListRows.Count
sCCEmail = sCCEmail & tblEmailCC.DataBodyRange(nRow, 1).Value & "; "
Next nRow
dteEffectiveDate = Range("C" & mnDataStartRow).Value
sSignature = GetCorpEmailSig()
OutMail.To = sToEmail
OutMail.CC = sCCEmail
OutMail.Subject = "My Email Subject as at " & Format(dteEffectiveDate, "mmmm dd yyyy")
OutMail.HTMLBody = "<BODY style=font-size:11pt;font-family:Calibri>" & sSalutation & _
"<br><br>My main email body text<br><br>Regards," & _
"<br>" & Mid(Application.UserName, InStr(1, Application.UserName, ",") + 2) & "</BODY>" & sSignature
If Dir(GetOutputPath) <> "" Then
OutMail.Attachments.Add (GetOutputPath)
End If
OutMail.Display
Set OutMail = Nothing
Set OutApp = Nothing
Exit Sub
Private Function GetCorpEmailSig() As String
Dim sSigFilename As String
Dim fso As Object
Dim ts As Object
sSigFilename = Environ("appdata") & "\Microsoft\Signatures\My Company Name.htm"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sSigFilename).OpenAsTextStream(1, -2)
GetCorpEmailSig = ts.ReadAll
ts.Close
End Function
请求创建金字塔路由以创建新资源。我的应用程序使用遍历,这适用于PUT
和GET
:
POST
由于config.add_route('myroute', '/resources/*traverse')
在URL中应该有新的资源名称,这显然不适用于PUT
,因为最后有一个未知资源,因此遍历失败。我尝试使用混合URL分派和遍历方法为PUT
创建新路由:
PUT
当且仅当仅存在要遍历的路径段时,此方法才有效。新资源的名称可用config.add_route('myroute_put', '/resources/{path}/{new}', traverse='/{path}', request_method='PUT')
如果我们处于根级别,没有任何东西可以遍历,我们仍然可以通过制作辅助路径来实现此目的:
request.matchdict['new']
但是,这不是一个真正的解决方案,因为如果有多个需要遍历的路径段,config.add_route('myroute_put_root', '/resources/{new}', reqeust_method='PUT')
仍然不匹配,例如URL:{{1 }}
答案 0 :(得分:2)
此Stack Overflow问题:Pyramid traversal HTTP PUT to a URI that doesn't exist提出了一种解决方案,可以创建不同的 NewResource 上下文类型来表示新资源。然后,资源类的__getitem__()
方法可以始终返回 NewResource ,如果它找不到所请求的子项。然后,可以为 NewResource 上下文和PUT
request_method设置视图配置。
这几乎可行,除非始终返回 NewResource ,而未找到孩子而不是提出KeyError
,它会破坏使用命名视图作为URL下属的能力。例如,网址:/resources/path1/path2/my_view
会错误地返回my_view
的 NewResource 上下文,而不是将其用作view_name(如果存在)。
到目前为止,我发现这个问题的最佳解决方法是创建一个首先使用默认遍历算法的自定义Pyramid Traversal算法,但如果失败则会检查request.method
是否为PUT
。如果是,则返回 NewResource 的上下文,否则返回遍历的结果。