C# 学习 txt -- excel txt -- json
在Unity3D 中使用,需要配置环境,\Assets\Plugins
Txt --> Excel
using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; using LitJson; using UnityEngine;public class DataNode {public string CopyName;public string CopyRace;public string CopyProfession; }public class DataCenter {public List<DataNode> List;public DataCenter(){List =new List<DataNode>();} } public class ToJson : MonoBehaviour {private string _txtPath;private string _jsonPath;// Use this for initializationvoid Start (){_jsonPath = Application.streamingAssetsPath + "/CopyInfo.json";_txtPath = Application.streamingAssetsPath + "/CopyInfo.txt";TextToJson();ReadJsonFromJsonPath();}private void TextToJson(){DataCenter dc = new DataCenter();using (StreamReader reader = new StreamReader(_txtPath, Encoding.UTF8)){string temp = string.Empty;while (!string.IsNullOrEmpty(temp = reader.ReadLine())){string[] infos = temp.Split('_');DataNode _node = new DataNode();_node.CopyName = infos[0];_node.CopyRace = infos[1];_node.CopyProfession = infos[2];dc.List.Add(_node);}}string jsonData = JsonMapper.ToJson(dc.List);File.WriteAllText(_jsonPath,jsonData);}private void ReadJsonFromJsonPath(){string jsonData = File.ReadAllText(_jsonPath);List<DataNode> nodes = JsonMapper.ToObject<List<DataNode>>(jsonData);Debug.Log(nodes.Count);}// Update is called once per framevoid Update () {} }
Txt --> Json
using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; using UnityEngine; using Excel; using OfficeOpenXml; using Excel.Core; using System.Data; using OfficeOpenXml.Style; using UnityEditor; using LitJson; using UnityEngine.Analytics;class CopyInfo {public string CopyName;public string CopyRace;public string CopyProfession;public CopyInfo(string name, string race, string profession){CopyName = name;CopyRace = race;CopyProfession = profession;} } public class ToExcel : MonoBehaviour {private List<GameObject> _copyList;private List<CopyInfo> _copyInfoList;private string _excelPath;private string _path;// Use this for initializationvoid Start (){_path = Application.streamingAssetsPath + "/CopyInfo.txt";_excelPath = Application.streamingAssetsPath + "/CopyInfo.xlsx";_copyList = new List<GameObject>();_copyInfoList = new List<CopyInfo>();ReadFileToList(_copyInfoList,_path);WriteExcel(_copyInfoList);}private void ReadFileToList(List<CopyInfo> list, string path){using (StreamReader reader = new StreamReader(path,Encoding.UTF8)){string tempstr = string.Empty;while (!string.IsNullOrEmpty(tempstr = reader.ReadLine())){string[] tmpInfos = tempstr.Split('_');list.Add(new CopyInfo(tmpInfos[0], tmpInfos[1], tmpInfos[2]));}}}private void WriteExcel(List<CopyInfo> list){FileInfo excelInfo = new FileInfo(_excelPath);if (excelInfo.Exists){excelInfo.Delete();excelInfo = new FileInfo(_excelPath);}using (ExcelPackage package = new ExcelPackage(excelInfo)){ExcelWorksheet sheet = package.Workbook.Worksheets.Add("TestInfo");sheet.Cells[1, 1].Value = "名字";sheet.Cells[1, 2].Value = "种族";sheet.Cells[1, 3].Value = "职业";for (int i = 0; i < _copyInfoList.Count; i++){sheet.Cells[2 + i, 1].Value = _copyInfoList[i].CopyName;sheet.Cells[2 + i, 2].Value = _copyInfoList[i].CopyRace;sheet.Cells[2 + i, 3].Value = _copyInfoList[i].CopyProfession;}sheet.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;sheet.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center;sheet.Cells.Style.Font.Bold = false;sheet.Cells.Style.Font.Name = "黑体";sheet.Cells.Style.Font.Size = 15;sheet.Cells.AutoFitColumns(30,50);package.Save();}AssetDatabase.Refresh();} }
转载于:https://www.cnblogs.com/ck-hhh/p/9917349.html
C# 学习 txt -- excel txt -- json相关推荐
- 《崔庆才Python3网络爬虫开发实战教程》学习笔记(5):将爬虫爬取到的数据存储到TXT,Word,Excel,Json等文件中
本篇博文是自己在学习崔庆才的<Python3网络爬虫开发实战教程>的学习笔记系列,此套教程共5章,加起来共有34节课,内容非常详细丰富!如果你也要这套视频教程的话,关注我公众号[小众技术] ...
- 如何快速合并多个CSV / Excel / txt 文件
最近,一个师姐(医学博士)拿到一批相同表头的 CSV 文件,想要它们合并在一起.不会写代码,只能用 EXCEL 打开文件,手动粘贴复制. 但是,又遇到问题了,她的 EXCEL 非常大,有的一个都有 5 ...
- 如何将TXT,EXCEL或CSV数据导入ORACLE到对应表中
如何将TXT,EXCEL或CSV数据导入ORACLE到对应表中 2011-05-12 14:19 方法一,使用SQL*Loader 这个是用的较多的方法,前提必须oracle数据中目的表已经 ...
- Excel Txt 字符集设置
Excel Txt 字符集设置都是在保存文档的时候设置的,而默认的字符集设置则是根据当前的系统,一般我们的windows系统都是GBK编码.
- Python将txt文件转为json文件
python将txt文件转为json文件 txt文件中内容: [*]www.xiaoyang.1 [*]www.xiaoyang.12 [*]www.xiaoyang.135 [*]www.xiaoy ...
- linux读取excel并导入mysql_mysql命令行的导入导出sql,txt,excel(都在linux或windows命令行操作)(转自筑梦悠然)...
Mysql导入导出sql,txt,excel 首先我们通过命令行进入到mysql安装目录的bin目录下,比如我输入的命令行为: d: cd D:/wamp/bin/mysql/mysql5.6.17 ...
- RoBERTa中的merge.txt和vocab.json是什么?
背景 在使用其他组织或个人发布的RoBERTa预训练模型时,一般除了模型文件之外还会有merges.txt和vocab.json.相比于BERT只需要一个vocab.txt,为何RoBRETa需要2个 ...
- matlab读取txt/excel文件并画图的方法
matlab读取txt/excel文件为矩阵,并进行画图的方法 1. matlab准备 如果没有matlab的话,只需要到学校网站上下载,按照步骤就可以安装.THU的下载地址如下: THU matla ...
- mysql gui 导入数据_在RGui中实现数据源的导入(数据框,.txt,excel,MySQL)
数据框中数据导入 > mydata + gender=character(0), + weight=numeric(0)) > mydata Warning message: In edi ...
最新文章
- 学习笔记——matplotlib学习
- 数据结构——Java Stack 类
- QT的QMatrix类的使用
- SSIS 执行变量中的脚步输出列顺序与SQL查询列顺序不同
- map 循环_被问到Spring循环依赖怎么解决?秀给面试官看!内附图解
- 让皮肤美白细致的七大DIY - 生活至上,美容至尚!
- 面试出现频率超高的一道算法题
- Atitit 前端测试最简化内嵌web服务器 php 与node.js 目录 1.1. php内置Web Server	1 1.2. Node的	2 Node的比较麻烦些。。Php更加简单
- 计算机数据处理规模大小分为,计算机组成原理题集样稿.doc
- 淘宝/天猫获得淘口令真实url API
- Arduino UNO数据手册(新手入门)
- C语言数组制作拼图游戏,C语言例子自制拼图游戏
- Android Studio模拟器如何运行apk文件
- 用户控制 键盘鼠标自定义 脚本
- Win7下使用wubi.exe安装Ubuntu系统
- Imagination异构计算平台力助AI芯片厂商加速冲击110亿美元市场 | AIIA 2020
- 你是真的“C”——详解函数递归+求解青蛙跳台阶问题
- 三、支持GPT硬盘格式启动的U盘PE
- python的truncate()函数
- intell idea怎么恢复默认设置