<data name="******" xml:space="preserve">
<value>*******</value>
<comment>******</comment>
</data>
Resource 文件在项目中多数被应用为国际化词条的资源文件
当数据量较大时维护会较为麻烦
作为一个程序猿没有什么是一个程序解决不了的 如果有那就再写一个程序
本文介绍 读取 excel 并向resource 文件中写入数据
nuget package 使用 npoi 方便从 excel中读取数据
将会通过此方式读取数据源
string path = "file path";
XSSFWorkbook _workbook;
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
{
_workbook = new XSSFWorkbook(file);
}//读取文件后释放掉流
XSSFSheet sheet = _workbook.GetSheetAt(0) as XSSFSheet;
IEnumerator rows = sheet.GetRowEnumerator();
while (rows.MoveNext())
{
XSSFRow row = (XSSFRow)rows.Current;
string str = row.Cells[0].ToString();
}
对 resx 资源文件写入
resx文件为 xml 结构资源文件 可以通过 linq to xml 方式写入数据
Data 数据节点在 root 节点中包含
<data name="******" xml:space="preserve">
<value>*******</value>
<comment>******</comment>
</data>
string path = "resx file path";
XDocument xdoc = XDocument.Load(dir + "Strings.vi-vn.resx");
var ele = xdoc.Element("root");
XElement tempEle = new XElement("data",
new XAttribute("name", ""),
new XAttribute(XNamespace.Xml + "space", "preserve"),
new XElement("value", "")
);
关于 xml 空白字符节点创建方式
https://msdn.microsoft.com/en-us/library/system.xml.linq.xnamespace.xml(v=vs.110).aspx