Skip to content

realblues/ExcelToObject

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExcelToObject

Read excel file into C# object.

Summary image

Features

  • Unity 4/5 compatible
  • Single DLL
  • Support Office Open XML format (.xlsx)
  • MIT License

Usage

  • Table is marked with a name in brackets [Table Name].

#1) Simple case

  • Read table into List<T>

Table

Code

public class EnemyData
{
	public string id;
	public EnemyType type;
	public StageType matchStageType;
	public int hp;
	public float atkSpeed;
	public int gainPoint;
	public float atkSpeed_Modify;
	public string color;
}
 
public void LoadFromExcel(string filePath)
{
	var excelReader = new ExcelToObject.ExcelReader(filePath);
	List<EnemyData> enemy = excelReader.ReadList<EnemyData>("EnemyData");
}

#2) Array/List case

  • A property can be a array or List<T>
  • It consists with same column name.
  • Column name can be distinguished by '#' notation. (postfix after '#' is ignored)

Table

Code

public class RatioData
{
	public int maxCount;
	public float[] ratio;
}
 
List<RatioData> ratio = excelReader.ReadList<RatioData>("RatioData");

#3) Dictionary case

  • A property can be a Dictionary<TKey,TValue>
  • It consists with same column name.
  • Key value is specified in '#' postfix
  • Key can be any type which is convertible to.

Table

Code

public class StagePhaseData
{
	public StageType type;
	public float interval;
	public int maxCount;
	public float ratio_Npc;
	public Dictionary<EnemyType, float> ratio;
}
 
var stagePhase = excelReader.ReadList<StagePhaseData>("StageData");

#4) Result can be Dictionary<TKey,T>

  • Result can be Dictionary<TKey, TValue>
  • Specify key column name for dictionary.

Table

Code

public class ModData
{
	public float spawnInterval_Modify;
}
 
Dictionary<StageType, ModData> modData;
modData = excelReader.ReadDictionary<StageType, ModData>("StageModifyData", "type");

Details

  • By default, every sheet in excel wil be searched for a table.
  • Several APIs are provided for more refined control.

License

MIT License

Refer to License file

Download

ExcelToObject.dll


EOF

About

Read excel file into C# object.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%