Let excel be the configuration
$ dotnet add package ExcelConfigExcelConfig is quick tool to operate excel be the configuration.
📃 demo config
🔗 store server
🔗 ExcelConfig.StoreAPI Nuget
var cfg = new AppConfigFile("./999/app.config.xlsx");
Console.WriteLine(cfg.Text("ExcelConfig版本"));
string Text(string key)
decimal Number(string key)
string[] Array(string key)
bool YesOrNo(string key)
void WriteYesOrNo(string key, bool value)
void WriteValue(string key, string value)
string YES = "是的";
string NO = "不是";
char ArraySplitChar = ';';
string SHEET_Global = "全局";
string CONFIG_DEFAULT = "app";
string CONFIG_SUFFIX = ".config.xlsx";
string FIELD_ExtraConfigPath = "额外配置目录";
string SHEET_ExtraConfig = "额外配置目录";
string COLUMN_KEY = "名称";
string COLUMN_VALUE = "值";
// 全局配置文件路径,,默认类库所在目录
// * 您需要确认配置的目录存在,不存在需要先行创建
string CONFIG_PATH = string.Empty;
xlsx template file related operations, the main function is to replace the specified cell and output the specified format table.
var template = new ExcelTemplateFile("./999/app.config.xlsx");
template.TemplateOut(new { TEST = "测试" }, "./test.xlsx");
var x = ExcelFile.Load("./999/app.config.xlsx", "全局");
var xw = x.Read(2,3).Text;
foreach (var line in x.ReadAllLine())
{
foreach (var line_key in line.Keys)
Console.WriteLine(line_key + ": " +line.Text(line_key));
}
using (var fs1 = File.Open("./999/app.config.xlsx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var cfg = new AppConfigStreamFile(fs1);
Console.WriteLine(cfg.Text("ExcelConfig版本"));
Console.WriteLine(cfg.Text("ExcelConfig版本"));
}
using (var fs1 = File.Open("./999/app.config.xlsx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var template = new ExcelTemplateStreamFile(fs1);
using (var mem = new MemoryStream())
{
template.TemplateOut(new { TEST = "测试" }, mem);
;
using (var fs2 = File.Create("test.xlsx"))
{
mem.CopyTo(fs2);
}
}
}
use ( )
Apache License 2.0