Indexing the Macros
To adapt the result to the user profile, use a code such as
Speeding Up the Rendering On_Before_Create_Analytic_Report
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
Principle:
1.The incoming report is pasted to a temporary file
2.Changes are brought to this temporary file
3.The line Context.CallingContextAnalyticReporting.CallingReportName = tempFile indicates that this temporary file becomes the report to render.
Testing the Description On_Insert_Article_Reference
Refer to How to Insert an Article or a Set Using its Reference or Description.