This is the fourth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021
The Unity of small science
As always, here are some popular science tips from Unity:
- Unity is a real-time 3D interactive content creation and operation platform.
- All creators, including game development, art, architecture, car design, film and television, use Unity to bring their ideas to life.
- The Unity platform offers a comprehensive suite of software solutions for creating, operating and monetizing any real-time interactive 2D and 3D content on mobile, tablet, PC, game console, augmented reality and virtual reality devices.
- You can also simply think of Unity as a game engine that can be used to make professional games!
Learn Unity
How to read Excel files in Unity
To read Excel files in Unity, you need to import two DLLS: Excel. DLL and icsharpCode. SharpZipLib
There is actually a System.Data. DLL to import backwards, but the new version of Unity comes with it so you don’t need to import it
But the above two Dll files must be imported! The download link of the above DLL file is here
We will beThe DLL file
The importThe Plugins folder in Unity
Under the
Then call it in code as shown in the following example:
using Excel;
using System.Data;
using System.IO;
using UnityEngine;
public class ExcelDemo : MonoBehaviour
{
void Start()
{
// Set the path to the file to read
string FilePath = Application.dataPath + "/StudentName.xlsx";
// Read the file
FileStream stream = File.Open(FilePath, FileMode.Open, FileAccess.Read);
// Read the Excel file
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();
int columns = result.Tables[0].Columns.Count;
int rows = result.Tables[0].Rows.Count;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
string nvalue = result.Tables[0].Rows[i][j].ToString();
// Print the contents of the Excel fileDebug.Log(nvalue); }}}}Copy the code
The script reads isAssets folder
Under theStudentName.xlsx
Hanging the script in the scene looks like this:The CSDN download link for this library file is here:Download.csdn.net/download/zh…Need can be downloaded experience