最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Unity讀取Excel文件轉(zhuǎn)換XML格式文件

 更新時(shí)間:2020年06月21日 12:48:16   作者:于子瀟  
這篇文章主要為大家詳細(xì)介紹了Unity讀取Excel文件轉(zhuǎn)換XML格式文件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity讀取Excel文件轉(zhuǎn)換XML格式文件的具體代碼,供大家參考,具體內(nèi)容如下

此方法用到excel.dll

下載連接 點(diǎn)擊打開(kāi)鏈接

using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Xml;
using Excel;
using System.Data;
 
/// <summary>
/// 創(chuàng)建XML表
/// </summary>
public class CreateXML : MonoBehaviour
{
 /// <summary>
 /// 表頭
 /// </summary>
 public const string xmlRoot = "FZW_MASK_XML_TABLE";
 
 //Excel名字
 public string ExcelPathName;
 
 //xml文件路徑;
 private string Path;
 //表文件名
 public string xmlName = "XMLTABLE.xml";
 //表名
 public string xmlTabeName = "XMLTABLE";
 
 //第一行字段
 private string[] tableTop;
 
 //表List
 private List<string[]> tableList=new List<string[]>();
 
 
 private void Awake()
 {
  //設(shè)置路徑
  Path = Application.streamingAssetsPath + "/XMLTable/" + xmlName;
 
  //讀取Excel
  ReadExcel(ExcelPathName);
 }
 
 
 /// <summary>
 /// 讀Excel
 /// </summary>
 /// <param name="ExcelPath"></param>
 /// <returns></returns>
 public void ReadExcel(string ExcelPath)
 {
  //excel文件位置 /MaskGame/ReadExcel/excel文件名
  FileStream stream = File.Open(Application.dataPath + "/MaskGame/ReadExcel/" + ExcelPath, FileMode.Open, FileAccess.Read);
  IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
 
  DataSet result = excelReader.AsDataSet();
 
  int rows = result.Tables[0].Rows.Count;//獲取行數(shù)(多少行信息)
  int columns = result.Tables[0].Columns.Count;//獲取列數(shù)(多少列字段)
  
  
  //初始化字段
  tableTop = new string[columns];
  
 
  //存字段
  for (int i = 0; i < columns; i++)
  {
   tableTop[i]= result.Tables[0].Rows[0][i].ToString();
  }
 
  //從第二行開(kāi)始讀 讀信息
  for (int i = 1; i < rows; i++)
  {
   //臨時(shí)表
   string[] table = new string[columns];
   //賦值表信息
   for (int j = 0; j < columns; j++)
   {
    string nvalue = result.Tables[0].Rows[i][j].ToString();
    table[j] = nvalue; 
   }
   //添加到List
   tableList.Add(table);
  }
 }
 
 /// <summary>
 /// 創(chuàng)建表格
 /// </summary>
 private void CreateXMLTable()
 {
  //路徑錯(cuò)誤
  if (File.Exists(Path)) return;
 
  //xml對(duì)象;
  XmlDocument xmll = new XmlDocument();
  //跟節(jié)點(diǎn)
  XmlElement Root = xmll.CreateElement(xmlRoot);
 
  for (int i = 0; i < tableList.Count; i++)
  {
   XmlElement xmlElement = xmll.CreateElement(xmlTabeName);
   xmlElement.SetAttribute(tableTop[0], tableList[i][0]);
 
   for (int j = 0; j < tableTop.Length-1; j++)
   {
    XmlElement infoElement = xmll.CreateElement(tableTop[j + 1]);
    infoElement.InnerText = tableList[i][j + 1];
    xmlElement.AppendChild(infoElement);
   }
   Root.AppendChild(xmlElement);
  }
 
  xmll.AppendChild(Root);
  xmll.Save(Path);
 
 }
 
 void OnGUI()
 {
  if (GUI.Button(new Rect(200, 200, 500, 500), "創(chuàng)建XML表"))
  {
   CreateXMLTable();
   Debug.Log("創(chuàng)建成功: " + Path);
  }
  
 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論

合作市| 炉霍县| 拉萨市| 皋兰县| 陈巴尔虎旗| 九龙坡区| 黄龙县| 新宁县| 胶南市| 临海市| 海林市| 恩平市| 九江市| 遂溪县| 阿巴嘎旗| 喀喇| 长武县| 昌图县| 瓮安县| 礼泉县| 汾西县| 正阳县| 广安市| 华坪县| 闵行区| 高台县| 青田县| 苍南县| 丹阳市| 德保县| 历史| 土默特左旗| 西昌市| 南江县| 蓝山县| 斗六市| 铁力市| 兴城市| 微博| 都兰县| 苏尼特左旗|