mini-software / MiniExcel

Fast, Low-Memory, Easy Excel .NET helper to import/export/template spreadsheet (support Linux, Mac)

Home Page:https://www.nuget.org/packages/MiniExcel/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SaveAs by empty IEnumerable<T> without header

shps951023 opened this issue · comments

JsonNet

void Main()
{
	{
		object rows = new List<Demo>(){ };
		var json = JsonConvert.SerializeObject(rows);
		Console.WriteLine(json); //[]	
	}
	{
		object rows = new List<Demo>(){ new Demo{}};
		var json = JsonConvert.SerializeObject(rows);
		Console.WriteLine(json); //[{"MyProperty1":null,"MyProperty2":null}]
	}
	{
		object rows = new List<Demo>() { new Demo {Demo2s=new List<Demo2>()} };
		var json = JsonConvert.SerializeObject(rows);
		Console.WriteLine(json); //[{"MyProperty1":null,"MyProperty2":null,"Demo2s":[]}]
	}
	{
		object rows = new List<Demo>() { new Demo { Demo2s = new List<Demo2>() {new Demo2()} } };
		var json = JsonConvert.SerializeObject(rows);
		Console.WriteLine(json); //[{"MyProperty1":null,"MyProperty2":null,"Demo2s":[{"MyProperty1":null,"MyProperty2":null}]}]
	}
}

// You can define other methods, fields, classes and namespaces here
public class Demo
{
	public string MyProperty1 { get; set; }
	public string MyProperty2 { get; set; }
	public List<Demo2> Demo2s { get; set; }
}

public class Demo2
{
	public string MyProperty1 { get; set; }
	public string MyProperty2 { get; set; }
}

Now default empty Enumerable like jsonnet
If want to have header columns need to specify generic type

MiniExcel.SaveAs<YourType>(parameter);

image
image
image

v0.18.0 support this.