This article shares the specific code for Unity to read Excel files to convert XML format files for your reference. The specific content is as follows
This method is used
Download the link Click to open the link
using ; using UnityEngine; using ; using ; using Excel; using ; /// <summary> /// Create XML table/// </summary> public class CreateXML : MonoBehaviour { /// <summary> /// Table header /// </summary> public const string xmlRoot = "FZW_MASK_XML_TABLE"; //Excel name public string ExcelPathName; //xml file path; private string Path; //Table file name public string xmlName = ""; //Table name public string xmlTabeName = "XMLTABLE"; //First line field private string[] tableTop; //Table List private List<string[]> tableList=new List<string[]>(); private void Awake() { //Set the path Path = + "/XMLTable/" + xmlName; //Read Excel ReadExcel(ExcelPathName); } /// <summary> /// Read Excel /// </summary> /// <param name="ExcelPath"></param> /// <returns></returns> public void ReadExcel(string ExcelPath) { //excel file location /MaskGame/ReadExcel/excel file name FileStream stream = ( + "/MaskGame/ReadExcel/" + ExcelPath, , ); IExcelDataReader excelReader = (stream); DataSet result = (); int rows = [0].;//Get the number of rows (how many rows) int columns = [0].;//Get the number of columns (how many column fields) //Initialize field tableTop = new string[columns]; //Save fields for (int i = 0; i < columns; i++) { tableTop[i]= [0].Rows[0][i].ToString(); } //Read the information from the second line for (int i = 1; i < rows; i++) { //Temporary table string[] table = new string[columns]; //Assignment table information for (int j = 0; j < columns; j++) { string nvalue = [0].Rows[i][j].ToString(); table[j] = nvalue; } //Add to List (table); } } /// <summary> /// Create a table /// </summary> private void CreateXMLTable() { //Path error if ((Path)) return; //xml object; XmlDocument xmll = new XmlDocument(); //Follow the node XmlElement Root = (xmlRoot); for (int i = 0; i < ; i++) { XmlElement xmlElement = (xmlTabeName); (tableTop[0], tableList[i][0]); for (int j = 0; j < -1; j++) { XmlElement infoElement = (tableTop[j + 1]); = tableList[i][j + 1]; (infoElement); } (xmlElement); } (Root); (Path); } void OnGUI() { if ((new Rect(200, 200, 500, 500), "Create XML table")) { CreateXMLTable(); ("Created successfully: " + Path); } } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.