Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to reference DLL component in C # code for QM2
#1
In qm3, it is very easy to create a doc document with the following code, It refers to GemBox.Document.dll  component
note:
Set DLL path: C:\Users\Administrator\Desktop\GemBox.Document.dll
Set Doc path: C:\Users\Administrator\Desktop\hello.docx

How to reference DLL component in C # code for QM2? Thanks in advance

In addition, how to generate DLL, exe,  code formatting? in qm3

Qm3 is very good and promising
Smile

QM3 code:

C# code:
// script "doc_cs.cs" /*/ r C:\Users\Administrator\Desktop\GemBox.Document.dll; /*/ //.
using Au; using System; using GemBox.Document;
partial class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args) { //;;;


        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = new DocumentModel();

        Section section = new Section(document);
        document.Sections.Add(section);

        Paragraph paragraph = new Paragraph(document);
        section.Blocks.Add(paragraph);

        Run run = new Run(document, "Hello World!");
        paragraph.Inlines.Add(run);

        document.Save(@"C:\Users\Administrator\Desktop\hello.docx");


}
}

QM2 Code:

Macro M3
Trigger A3     Help - how to add the trigger to the macro
Code:
Copy      Help
CsScript x.AddCode("")

x.Call("Program.Main")


#ret
using GemBox.Document;

class Program
{
,static void Main()
,{
,,// If using Professional version, put your serial key below.
,,ComponentInfo.SetLicense("FREE-LIMITED-KEY");

,,DocumentModel document = new DocumentModel();

,,Section section = new Section(document);
,,document.Sections.Add(section);

,,Paragraph paragraph = new Paragraph(document);
,,section.Blocks.Add(paragraph);

,,Run run = new Run(document, "Hello World!");
,,paragraph.Inlines.Add(run);

,,document.Save(@"C:\Users\Administrator\Desktop\hello.docx");
,}
}


Attached Files
.zip   GemBox.Document.dll.zip (Size: 1.25 MB / Downloads: 170)
#2
Code:
Copy      Help
CsScript x.AddCode("")
x.SetOptions("references=C:\Users\Administrator\Desktop\GemBox.Document.dll")
x.Call("Program.Main")
#3
Error (RT) in <open ":1: /9">M3:  0x80131600, 
    <macro "Scripting_Link /7 7 2 ''M3''">M3(7,7): error CS0246: The type or namespace name 'GemBox' could not be found (are you missing a using directive or an assembly reference?).    <help #IDP_ERR>?
#4
also in your c# code
need to change
Code:
Copy      Help
class Program
{
,static void Main()

to this
 
Code:
Copy      Help
public class Program
{
,public static void Main()

copy the dll to qm program folder
in win10 its
C:\Program Files (x86)\Quick Macros 2

then change code to this
Code:
Copy      Help
CsScript x.AddCode("")
x.SetOptions("references=$qm$\GemBox.Document.dll")
x.Call("Program.Main")
#5
@kevin
Thank you for your help

don't need this line of code:
x.SetOptions("references=C:\Users\Administrator\Desktop\GemBox.Document.dll")

copy the dll to qm program folder
C:\Program Files (x86)\Quick Macros 2

Package into exe, and put the EXE file and DLL in the same folder


Final code:
Macro M3
Trigger A3     Help - how to add the trigger to the macro
Code:
Copy      Help
CsScript x.AddCode("")
x.Call("Program.Main")


#ret
using GemBox.Document;

public class Program
{
,public static void Main()
,{
,,// If using Professional version, put your serial key below.
,,ComponentInfo.SetLicense("FREE-LIMITED-KEY");

,,DocumentModel document = new DocumentModel();

,,Section section = new Section(document);
,,document.Sections.Add(section);

,,Paragraph paragraph = new Paragraph(document);
,,section.Blocks.Add(paragraph);

,,Run run = new Run(document, "Hello World!");
,,paragraph.Inlines.Add(run);

,,document.Save(@"C:\Users\Administrator\Desktop\hello.docx");
,}
}

For QM3 How to modify the relative path of reference DLL?

// script "doc_cs.cs" /*/ r C:\Users\Administrator\Desktop\GemBox.Document.dll; /*/ //.

How to use variables?

Macro Macro8
Code:
Copy      Help
str doc_path="C:\Users\Administrator\Desktop\test_doc.docx"
str code=
F
;using GemBox.Document;
;
;public class Program
;{
,;public static void Main()
,;{
,,;// If using Professional version, put your serial key below.
,,;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
;
,,;DocumentModel document = new DocumentModel();
;
,,;Section section = new Section(document);
,,;document.Sections.Add(section);
;
,,;Paragraph paragraph = new Paragraph(document);
,,;section.Blocks.Add(paragraph);
;
,,;Run run = new Run(document, "Hello World!");
,,;paragraph.Inlines.Add(run);
;
,,;document.Save(@"{doc_path}");
,;}
;}

CsScript x.AddCode(code)
x.Call("Program.Main")
#6
like this in qm
Code:
Copy      Help
str doc_path.expandpath("$Desktop$\test_doc.docx")
str code=
F
;using GemBox.Document;
;
;public class Program
;{{
,;public static void Main()
,;{{
,,;// If using Professional version, put your serial key below.
,,;ComponentInfo.SetLicense("FREE-LIMITED-KEY");
;
,,;DocumentModel document = new DocumentModel();
;
,,;Section section = new Section(document);
,,;document.Sections.Add(section);
;
,,;Paragraph paragraph = new Paragraph(document);
,,;section.Blocks.Add(paragraph);
;
,,;Run run = new Run(document, "Hello World!");
,,;paragraph.Inlines.Add(run);
;
,,;document.Save(@"{doc_path}");
,;}
;}

CsScript x.AddCode(code)
x.Call("Program.Main")

or c# way 
Code:
Copy      Help
CsScript x.AddCode("")
;x.SetOptions("references=$qm$\GemBox.Document.dll")
x.Call("Program.Main")


#ret
using GemBox.Document;
using System;

public class Program
{
,public static void Main()
,{
,,// If using Professional version, put your serial key below.
,,ComponentInfo.SetLicense("FREE-LIMITED-KEY");

,,DocumentModel document = new DocumentModel();

,,Section section = new Section(document);
,,document.Sections.Add(section);

,,Paragraph paragraph = new Paragraph(document);
,,section.Blocks.Add(paragraph);

,,Run run = new Run(document, "Hello World!");
,,paragraph.Inlines.Add(run);
,,
,,string docPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
,,document.Save(String.Format("{0}\\hello.docx" ,docPathPath));
,}
}
#7
Thanks for sharing the code, good example

It's easier to use variables in qm3 without considering escape
#8
Quote:For QM3 How to modify the relative path of reference DLL?
.NET dlls should be in QM3 folder's subfolder Libraries. Then select in the Properties dialog, Assembly button. It will add

C# code:
/*/ ifRunning warn_restart; r Libraries\DllName.dll; /*/ //.


Forum Jump:


Users browsing this thread: 1 Guest(s)