Index de macros
Pour adapter le résultat au profil utilisateur, utiliser un code tel que
Accélérer le rendu Sur Avant Création d'Etat Analytique
Public Shared Sub EntryMethod(ByVal Es As Qdv.UserApi.IEstimate, ByVal Context As Qdv.UserApi.ICallingContext)
Try 'This is recommended to catch all errors to deliver proper error messages
'This is the entry point of your macro
'You can add your code here below...
Dim reportName As String = Context.CallingContextAnalyticReporting.CallingReportName
If reportName.ToLower.EndsWith("xlsx") Then
Dim theFileNameOnly As String = System.IO.Path.GetFileName(reportName)
If theFileNameOnly.ToLower = "Test_Report.xlsx".ToLower Then
'this is an Excel report
Dim response = MsgBox("Do you want to write 'REPLACED BY THE MACRO!' in cell A2 or the MATTER Sheet?", MsgBoxStyle.YesNoCancel, "Alter report template?")
If response = vbNo Then
'Just alter nothing, keep going
ElseIf response = vbyes Then
'Get a temporary file name
Dim tempFile As String = System.IO.Path.GetTempFileName & ".xlsx"
Try
System.IO.File.Copy(reportName, tempFile, True)
Catch ex1 As Exception
MsgBox("Cannot copy report file to temp file!" & vbCrLf & vbCrLf & ex1.Message, MsgBoxStyle.Critical, "")
Context.MustCancel = True
Exit Sub
End Try
'We must use Excel VBA to rename the sheet because it we use SpreadsheetGear we would loose dynamic arrays
'A reference to Microsoft.Interop.Excel is required to use Excel Here. See references in the Build menu of this editor
'The reference must be taken from the QDV folder as shown in this macro
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim wbk As Microsoft.Office.Interop.Excel.Workbook = Nothing
Try
wbk = xlApp.Workbooks.Open(tempFile)
Dim wsh As Microsoft.Office.Interop.Excel.Worksheet = wbk.Worksheets("MATTER")
wsh.Range("A2").Value = "REPLACED BY THE MACRO!"
wbk.Save
Context.CallingContextAnalyticReporting.CallingReportName = tempFile 'Continue with modified file
Catch ex2 As Exception
MsgBox("Cannot alter sheet MATTER in the report!" & vbCrLf & vbCrLf & ex2.Message, MsgBoxStyle.Critical, "")
Context.MustCancel = True
Exit Sub
Finally
If Not IsNothing(wbk) Then
wbk.Close 'Make sure we always close it
End If
xlApp = Nothing
End Try
Else
Context.CallingContextAnalyticReporting.CallingReportName = ""
Context.MustCancel = True
Exit Sub
End If
End If
End If
Catch GeneralError As Exception 'Catches all error to get proper message
MessageBox.Show(GeneralError.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Context.MustCancel = True 'Cancel the event if it is called through an event
End Try
End Sub
Principe :
1.L'état entrant est copié dans un fichier temporaire
2.des changements sont apportés à ce fichier temporaire
3.la ligne Context.CallingContextAnalyticReporting.CallingReportName = tempFile indique que ce fichier temporaire devient l'état à rendre.
Test de la Description Sur Avant insertion de référence d'article
Voir Insérer un article ou un ouvrage par sa référence ou description.