当前位置:网站首页>Unity package exe to read and write excel table files
Unity package exe to read and write excel table files
2022-07-28 20:35:00 【Mark_ source】
Unity Read user configuration information when running , Export the information to be saved in the application to Excel form
1、 Import Excel Read plug-ins

2、 Import opens Windows File and folder tools ( I wrote it before )

3、 Usage method
1)、 New script , And define parameters
public Button saveBtn;
public Button readBtn;
private Action<string> readAction;
private Action<string> saveAction;
public Text des;2)、 Binding of events
private void Start()
{
saveBtn.onClick.AddListener(OpenFolder);
readBtn.onClick.AddListener(OpenFile);
saveAction += SaveFile;
readAction += GetFile;
}3)、 Function realization
public void OpenFile()
{
Mark.OpenDialogHelper.SelectFile(readAction, "Excel file (*.xlsx*)\0*.xlsx*"); // FBX file (*.fbx)\0*.fbx\0
}
public void OpenFolder()
{
Mark.OpenDialogHelper.SelectFolder(saveAction);
}
private void GetFile(string filePath)
{
Debug.Log(filePath);
Read(filePath);
}
private void SaveFile(string filePath)
{
Debug.Log(filePath);
Create(filePath);
}
private void Create(string path)
{
if (Directory.Exists(path))
{
string ph = path + "/" + "Tex2.xlsx";
FileInfo newFile = new FileInfo(ph);
if (newFile.Exists)
{
newFile.Delete();
newFile = new FileInfo(ph);
}
using (ExcelPackage package = new ExcelPackage(newFile))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("ModelInfo");// establish worksheet
CreateTitle(worksheet);
CreateContent(worksheet);
package.Save();
}
}
}
private void Read(string path)
{
StringBuilder sb = new StringBuilder();
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
{
sb.Clear();
using (ExcelPackage ep = new ExcelPackage(fs))
{
// Get all tables E:\Test\Text.xlsx
StringBuilder sb1 = new StringBuilder();
ExcelWorksheets worksheets = ep.Workbook.Worksheets;
for (int i = 1; i <= worksheets.Count; i++)
{
// The current worksheet
ExcelWorksheet sheet = worksheets[i];
// The current worksheet How many? Column
int columCount = sheet.Dimension.End.Column;
// The current worksheet How many? That's ok
int rowCount = sheet.Dimension.End.Row;
// From the first few lines \ Which column starts reading data , It depends on the specific situation
int startRow = 2;
int startColum = 1;
for (int j = startRow; j <= rowCount; j++)
{
sb1.Clear();
for (int k = startColum; k <= columCount; k++)
{
if (!string.IsNullOrEmpty(sheet.Cells[j, k].Text))
{
sb1.Append(sheet.Cells[j, k].Text+" ");
}
}
string str = $" At present Excel Table No {i} Table reading : The first {j} Row data :{sb1.ToString()}\n";
sb.Append(str);
}
}
}
des.text = sb.ToString();
}
}
private void CreateTitle(ExcelWorksheet worksheet)
{
worksheet.Cells[1, 1].Value = " Serial number ";
worksheet.Cells[1, 2].Value = " name ";
worksheet.Cells[1, 3].Value = " Number ";
worksheet.Cells[1, 4].Value = " Company ";
worksheet.Cells[1, 5].Value = " The unit price ";
worksheet.Cells[1, 6].Value = " Total price ";
worksheet.Cells[1, 7].Value = " remarks ";
}
private void CreateContent(ExcelWorksheet worksheet)
{
for (int i = 2; i <= 5; i++)
{
for (int j = 1; j <= 5; j++)
{
worksheet.Cells[i, j].Value = i * j;
}
}
}4、 Effect display

边栏推荐
- Solve the brick stacking problem (DP)
- Who cares about the safety of the battery when it ignites in a collision? SAIC GM has something to say
- LVS deployment Dr cluster
- Solve the problem that the nocturnal simulator cannot access the Internet after setting an agent
- [POC - proof of concept]
- Raspberry connects EC20 for PPP dialing
- PXE_ KS unattended system
- Representation of base and number 2
- Clock distribution of jesd204 IP core (ultrascale Series)
- Raspberry pie 4B parsing PWM
猜你喜欢
![Teach you how to draw a map with ArcGIS [thermal map]](/img/16/993da4678667884a98e1d82db37d69.png)
Teach you how to draw a map with ArcGIS [thermal map]

LVM logical volume

CNN convolution neural network learning process (weight update)
![Maximum exchange [greedy thought & monotonic stack implementation]](/img/ad/8f0914f23648f37e1d1ce69086fd2e.png)
Maximum exchange [greedy thought & monotonic stack implementation]

Other IPS cannot connect to the local redis problem solving and redis installation

【pytorch】LSTM神经网络

Classes and objects (medium)

js图表散点图例子

PXE_ KS unattended system
![[detailed use of doccano data annotation]](/img/40/c18cf8d5519328d707ed89fccb70ee.png)
[detailed use of doccano data annotation]
随机推荐
Solutions to the environment created by Anaconda that cannot be displayed in pycharm
太空游戏第12课: 盾牌
Raspberry connects EC20 for PPP dialing
[POC - proof of concept]
PXE_ KS unattended system
Pop up modal box
Linxu 【权限,粘滞位】
Method number problem for solving sum of numbers (knapsack problem)
[task01: getting familiar with database and SQL]
[pytorch] LSTM neural network
产品力大幅提升 新款福特探险者发布
Array out of bounds
DOS common commands
漂亮的蓝色背景表单输入框样式
Who cares about the safety of the battery when it ignites in a collision? SAIC GM has something to say
Wust-ctf2021-re school match WP
Networkx common operations summary (for personal use)
Raspberry pie 4B uses MNN to deploy yolov5 Lite
Torch. NN. Linear() function
Raspberry Pie 3 connected to WiFi