将Excel数据传输到Unity [英] Transferring Excel Data to Unity
问题描述
我在excel电子表格中有大量数据,我需要在Unity项目中传输一些数组.我一直在寻找一些方法,可能会尝试其中的一些方法,但是我还有另一个问题.是否可以在没有其他插件或工具的情况下将Excel数据传输到Unity数组?只是有基本的Unity吗?
正如@julienkay所说,如果excel文件是.csv,则可以将其视为纯文本文件,但但是怎么办??
如果您正在使用.xlsx,我建议使用 Microsoft.Office.Interop.Excel;
,它很容易使用,但要在Unity中正常工作并不容易,这就是为什么
I have a large list of data in an excel spreadsheet that I need to transfer a few arrays in my Unity project. I have been looking up a few methods and will likely try out a few of them, but I had another question. Is it possible to transfer Excel data to Unity arrays without an additional plug in or tool? Just with base Unity?
As @julienkay says, if the excel file is a .csv could be treated as a plain text file, BUT what if not?
If you are working with .xlsx I recommend to use Microsoft.Office.Interop.Excel;
, it's pretty easy to use, but not so easy to get it working in Unity, that's why this link could help you!
And this is a simple example on how to use the Interop.Excel methods, this code will create a dictionary filled with the titles and links for the books in this excel:
private void Exel()
{
Dictionary<string, string> linkTitleDict = new Dictionary<string, string>();
Application app = new Application();
Workbook excelWorkbook = app.Workbooks.Open(@"C:\Users\...\SpringerEbooks.xlsx");
Sheets excelSheets = excelWorkbook.Worksheets;
string currentSheet = "Table 1";
Worksheet excelWorksheet = (Worksheet)excelSheets.get_Item(currentSheet);
//
for (int i = initialRow; i < finalRow + 1; i++)
{
string bookTitle = (string)(excelWorksheet.Cells[i, 2] as Range).Value;
string bookLink = (string)(excelWorksheet.Cells[i, 5] as Range).Value;
linkTitleDict.Add(bookLink, bookTitle);
}
}
How the excel looks:
这篇关于将Excel数据传输到Unity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!