08-07-2025, 11:28 AM
Works here. Maybe not all Spire dlls are in your dll folder + runtimes subfolder.
// script "csRtCo_spire.doc.cs"
/*/ role exeProgram; outputPath %folders.Workspace%\exe\csRtCo_spire.doc; c CsScript.cs; /*/
/*/ c CsScript.cs; /*/
//print.clear();
//print.redirectConsoleOutput = true; //if using Console.WriteLine
string code = """
using Spire.Doc;
using System;
Au.print.it("C# script started");
string sDir = @"C:\Test\spire";
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, r: [@"C:\code\ok\.nuget\spire\Spire.Doc.dll"]);
//var c = CsScript.Compile(code, r: [folders.ThisApp + "Spire.Doc.dll"]); //if spire dlls are in the exe folder
if (c == null) return;
c.Run();