Is there any way to insert an existing macro into a existing excel file without using the excel library ? I need this to set the excel to print whole work book .I cannot use excel library because it will be done online in the server where installation of excel is not possible. I can however use the c#.net coding . I am using NPOI to generate the excel.
the macro is given below
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If printed = False Then
Cancel = True
printed = True
ActiveWorkbook.P开发者_如何学JAVArintOut
End If
End Sub
A different approach would be to convert the excel file to a pdf then print the pdf. There's a library for the conversion that seems to have a good reputation:
http://www.aspose.com/
The only other recognized way to manipulate excel is with the OLEDB or ACE providers, but they do not provide macro access as far as I am aware.
If you were able to reference the Excel dll, here's an MSDN article describing how to inject a macro:
http://support.microsoft.com/kb/303871
精彩评论