当前位置:网站首页>About the operation of unit file reading (I)
About the operation of unit file reading (I)
2022-04-23 18:36:00 【Meng Chen Shuangxi】
Make a note of unity How to read files
1. About Excel Read and write files :
The clue here comes from buying a Book , Title 《unity3D Game development ( The second edition )》, The author is Xuan Yusong. He mentioned using a DLL The plug-in can easily read, write and create files .Epplus This can be B Station or VS Package management can also be imported directly , Or you can come to me if you need . The code is as follows :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using OfficeOpenXml;
public class PrintExcel : MonoBehaviour
{
void Start()
{
LoadExcel();
AddExcel();
}
public static void LoadExcel()
{
string path = Application.dataPath + "/Excel/test.xlsx";
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (ExcelPackage excel=new ExcelPackage(fs))
{
ExcelWorksheets excelWorksheets = excel.Workbook.Worksheets;// Get all the forms
Debug.Log(" Table number :"+excelWorksheets.Count);
for (int i = 1; i <= excelWorksheets.Count; i++)// From the subscript 1 Start
{
ExcelWorksheet worksheet = excelWorksheets[i];
int colCount = worksheet.Dimension.End.Column;
Debug.Log(worksheet.Name);
for(int row = 1, count = worksheet.Dimension.End.Row; row <= count; row++)
{
for(int col = 1; col <= colCount; col++)
{
// Read the contents of each cell
var text = worksheet.Cells[row, col].Text;
Debug.Log(text);
}
}
}
}
}
}
public static void AddExcel()
{
string path = Application.dataPath + "/Excel/test.xlsx";
var file = new FileInfo(path);
using (ExcelPackage excel=new ExcelPackage(file))
{
ExcelWorksheet worksheet2 = excel.Workbook.Worksheets.Add("Sheet3");//( If it already exists, an error will be reported , So we need to judge here )
worksheet2.Cells[1, 1].Value = " Company name ";
worksheet2.Cells[1, 2].Value = " Address ";
excel.Save();
}
AssetDatabase.Refresh();
}
}
It should be noted that string path = Application.dataPath + “/Excel/test.xlsx”, The path must be written correctly , What I write in this code is to read all and show . And a little bit more for (int i = 1; i <= excelWorksheets.Count; i++), The table is actually subscript 1 At the beginning
2. About word Document reading
This is a long time ago , It's also found by checking someone else's code , The link can't be given . The code is as follows :
DirectoryInfo d = new DirectoryInfo(LoadVariables.rootPATH + "/"+LoadVariables.loadScene);// route
DirectoryInfo[] dc = d.GetDirectories();// Get the folder
FileInfo[] files = d.GetFiles("*.txt");// get txt file
Debug.Log(files.Length);
for (int i = 0; i < files.Length; i++)
{
string a=File.ReadAllText(LoadVariables.rootPATH + "/"+LoadVariables.loadScene+"/"+files[i].Name);// Read the file
}
版权声明
本文为[Meng Chen Shuangxi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231830134460.html
边栏推荐
- STM32 learning record 0008 - GPIO things 1
- WiFi ap6212 driver transplantation and debugging analysis technical notes
- Ucosiii transplantation and use, reference punctual atom
- QT error: no matching member function for call to ‘connect‘
- Daily network security certification test questions (April 12, 2022)
- How to virtualize the video frame and background is realized in a few simple steps
- Dynamically add default fusing rules to feign client based on sentinel + Nacos
- Solution to Chinese garbled code after reg file is imported into the registry
- 14 py games source code share the second bullet
- Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
猜你喜欢

Nodejs installation

Machine learning theory (8): model integration ensemble learning

实战业务优化方案总结---主目录---持续更新

Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash

Creation and use of QT dynamic link library

Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système

根据快递单号查询物流查询更新量

多功能工具箱微信小程序源码

Matlab tips (6) comparison of seven filtering methods

Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
随机推荐
Feign requests the log to be printed uniformly
Jeecg boot microservice architecture
Setting up keil environment of GD single chip microcomputer
ctfshow-web362(SSTI)
Error reported when running tensorboard: valueerror: duplicate plugins for name projector, solution
昇腾 AI 开发者创享日全国巡回首站在西安成功举行
How to restore MySQL database after win10 system is reinstalled (mysql-8.0.26-winx64. Zip)
Robocode tutorial 7 - Radar locking
Druid SQL和Security在美团点评的实践
Ucosiii transplantation and use, reference punctual atom
Teach you to quickly rename folder names in a few simple steps
Interpretation and compilation of JVM
The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an
QT add external font ttf
纠结
串口调试工具cutecom和minicom
Gson fastjason Jackson of object to JSON difference modifies the field name
Imx6 debugging LVDS screen technical notes
Query the logistics update quantity according to the express order number
SQL database syntax learning notes