从excel导入到 resource 文件

来源:互联网 发布:小满淘宝店 编辑:程序博客网 时间:2024/06/05 21:52

<data name="******" xml:space="preserve">    <value>*******</value>    <comment>******</comment></data>

Resource文件在项目中多数被应用为国际化词条的资源文件

当数据量较大时维护会较为麻烦

作为一个程序猿没有什么是一个程序解决不了的如果有那就再写一个程序 

本文介绍读取 excel 并向resource文件中写入数据


nugetpackage 使用 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




原创粉丝点击