欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Unity讀取Excel文件轉(zhuǎn)換XML格式文件的方法-創(chuàng)新互聯(lián)

不懂Unity讀取Excel文件轉(zhuǎn)換XML格式文件的方法?其實想解決這個問題也不難,下面讓小編帶著大家一起學習怎么去解決,希望大家閱讀完這篇文章后大所收獲。

我們提供的服務有:網(wǎng)站設計制作、網(wǎng)站設計、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、和林格爾ssl等。為超過千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術的和林格爾網(wǎng)站制作公司

此方法用到excel.dll

下載連接 點擊打開鏈接

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()
 {
  //設置路徑
  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();
  }
 
  //從第二行開始讀 讀信息
  for (int i = 1; i < rows; i++)
  {
   //臨時表
   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()
 {
  //路徑錯誤
  if (File.Exists(Path)) return;
 
  //xml對象;
  XmlDocument xmll = new XmlDocument();
  //跟節(jié)點
  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);
  }
  
 }
}

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

文章題目:Unity讀取Excel文件轉(zhuǎn)換XML格式文件的方法-創(chuàng)新互聯(lián)
網(wǎng)址分享:http://www.chinadenli.net/article24/disgce.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設網(wǎng)站導航動態(tài)網(wǎng)站定制網(wǎng)站品牌網(wǎng)站制作網(wǎng)頁設計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設