-
Notifications
You must be signed in to change notification settings - Fork 0
Create C# program to execute scripts
Scripts have to be saved in basic text file, for example: script.lxrw.
Now let's open your Visual Studio or VSCode. First import the nuget Lexerow package in your solution or project.
Create a program in C# and use it in this way:
using Lexerow.Core.System;
// create the core engine
LexerowCore core = new LexerowCore();
// load and execute the script
core.LoadExecScript("MyScript", "script.lxrw");
This is the smallest C# program you have to write.
It works in 3 stages:
1/ Load the script from the text file,
2/ Compile the script, parse the content, build a program with instructions to execute,
3/ Execute the program.
If an error occurs, see the final result object like this:
// load and execute the script
Result result= core.LoadExecScript("MyScript", "script.lxrw");
if(!Result.Res)
{
Console.WriteLine("Error code one: " + result.ListError[0].ErrorCode);
}
It's possible to get some information after the execution of a script:
-How many files processed,
-How many sheet processed,
-How many rows scanned,
-How many If conditions matches.
// load the script, compile it and then execute it
Result result = core.LoadExecScript("script", "script.lxrw");
//--display result insights
Console.WriteLine("Total files: " + result.Insights.FileTotalCount);
Console.WriteLine("Total Sheets: " + result.Insights.SheetTotalCount);
Console.WriteLine("Total rows scanned: " + result.Insights.RowTotalCount);
Console.WriteLine("Total IfCond Matched: " + result.Insights.IfCondMatchTotalCount);
It's possible to activate logs in the console, in a text file or in a csv file.
log levels are:
-Off: no log are sent.
-Info: High level. To log only functionnal information. The default log level.
-Debug: Information that is diagnostically helpful.
-Trace: Only to "trace" the code and trying to find one part of a function specifically.
LexerowCore core = new LexerowCore();
// set the log level to trace here (can be Off, Info or Debug)
core.Diagnostics.SetLogLevelTrace();
// display log to the console
core.Diagnostics.LogToConsole(true);
// logs are saved in text file, line by line
core.Diagnostics.SaveLogTxt(".\\Logs\\logs.txt");
// logs are saved formatted in csv file
core.Diagnostics.SaveLogCsv(".\\Logs\\logs.csv");
// load the script, compile it and then execute it
Result result = core.LoadExecScript("script", "script.lxrw");
By Pierlam, March 2026