当前位置:网站首页>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
边栏推荐
- In win10 system, all programs run as administrator by default
- Daily CISSP certification common mistakes (April 13, 2022)
- STM32学习记录0008——GPIO那些事1
- Ionic instruction set order from creation to packaging
- Daily network security certification test questions (April 13, 2022)
- 机器学习实战 -朴素贝叶斯
- 昇腾 AI 开发者创享日全国巡回首站在西安成功举行
- The vivado project corresponding to the board is generated by TCL script
- Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
- ctfshow-web361(SSTI)
猜你喜欢

Jeecg boot microservice architecture

解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本

使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA

With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate

On iptables

Teach you to quickly rename folder names in a few simple steps

STM32: LCD display

Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time

The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an

Setting up keil environment of GD single chip microcomputer
随机推荐
Error reported when running tensorboard: valueerror: duplicate plugins for name projector, solution
Query the logistics update quantity according to the express order number
Ucosiii transplantation and use, reference punctual atom
串口调试工具cutecom和minicom
教你用简单几个步骤快速重命名文件夹名
Quantexa CDI(场景决策智能)Syneo平台介绍
Iptables - L executes slowly
Use of regular expressions in QT
CISSP certified daily knowledge points (April 19, 2022)
The connection of imx6 network port is unstable after power on
iptables -L执行缓慢
Daily network security certification test questions (April 12, 2022)
SQL database syntax learning notes
Daily CISSP certification common mistakes (April 18, 2022)
Chondroitin sulfate in vitreous
解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
Resolves the interface method that allows annotation requests to be written in postman
Keil RVMDK compiled data type
If condition judgment in shell language
Nodejs installation