Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CsScript exec code
#1
The following two scripts do not throw any exceptions when executed, but they do not generate a DOCX file. Why?

Code:
Copy      Help
// script "csRtCo_spire.doc.cs"
/*/ role exeProgram; outputPath %folders.Workspace%\exe\csRtCo_spire.doc; c CsScript.cs; /*/ //.
script.setup(trayIcon: true, sleepExit: true);
//..

print.clear();

string code = """
using Spire.Doc;
using System;

string sDir = @"C:\Users\Administrator\Desktop";
string sTxt = "hello world!";
string sName = "hello.docx";
newDoc(sDir, sTxt, sName);

void newDoc(string sDir, string sTxt, string sName)
{
    Environment.CurrentDirectory = sDir;
    var doc = new Document();
    var section = doc.AddSection();
    var paragraph = section.AddParagraph();
    paragraph.AppendText(sTxt);
    doc.SaveToFile(sName, FileFormat.Docx2016);
}
"""
;

var c = CsScript.Compile(code);
if (c == null) return;

c.Run();


Code:
Copy      Help
// script "csRtCo_spire.doc2.cs"
/*/ role exeProgram; outputPath %folders.Workspace%\exe\csRtCo_spire.doc2; c CsScript.cs; /*/ //.
script.setup(trayIcon: true, sleepExit: true);
//..

print.clear();

string code = """
using Spire.Doc;
using System;

string sDir = @"C:\Users\Administrator\Desktop";
string sTxt = "hello world!";
string sName = "hello.docx";
newDoc(sDir, sTxt, sName);

void newDoc(string sDir, string sTxt, string sName)
{
    Environment.CurrentDirectory = sDir;
    var doc = new Document();
    var section = doc.AddSection();
    var paragraph = section.AddParagraph();
    paragraph.AppendText(sTxt);
    doc.SaveToFile(sName, FileFormat.Docx2016);
}
"""
;

var errors = new List<string>();

var c = CsScript.Compile(code, r: new[] { @"D:\RPA\spire\10.5.0\NET9.0\Spire.Doc.dll" }, errors: errors);

if (c == null) {
    Console.WriteLine("Failed to compile:");
    foreach (var error in errors) {
        Console.WriteLine(error);
    }

    return;
}


c.Run();


Messages In This Thread
CsScript exec code - by Davider - 08-03-2025, 03:40 AM
RE: CsScript exec code - by Gintaras - 08-03-2025, 03:49 AM
RE: CsScript exec code - by Davider - 08-03-2025, 04:05 AM
RE: CsScript exec code - by Gintaras - 08-03-2025, 04:15 AM
RE: CsScript exec code - by Davider - 08-03-2025, 04:34 AM
RE: CsScript exec code - by Gintaras - 08-03-2025, 04:39 AM
RE: CsScript exec code - by Davider - 08-03-2025, 04:50 AM
RE: CsScript exec code - by Gintaras - 08-03-2025, 05:08 AM
RE: CsScript exec code - by Davider - 08-03-2025, 05:26 AM
RE: CsScript exec code - by Gintaras - 08-03-2025, 05:49 AM
RE: CsScript exec code - by Davider - 08-03-2025, 06:03 AM
RE: CsScript exec code - by Davider - 08-06-2025, 11:46 PM
RE: CsScript exec code - by Gintaras - 08-07-2025, 11:28 AM
RE: CsScript exec code - by Davider - 08-07-2025, 02:02 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)