Skip to content

Excel sheet (xlsx) to C# code and json. dotnet global cli application.

License

Notifications You must be signed in to change notification settings

elky84/ExcelToDotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

54 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Website Made with Made with

Publish Nuget Github Package Publish Nuget Package Publish Nuget Tool Package

GitHub forks GitHub stars GitHub watchers GitHub followers

GitHub GitHub repo size in bytes GitHub code size in bytes

ExcelToDotnet

Getting started

Nuget.org

https://www.nuget.org/packages/ExcelToDotnet/

introduce

English

Excel To Dotnet Compatible Data (Enum, Class, JSON)

It can be said to be a converter that can be used in Unity, C# applications, etc.

An Excel Sheet with a set rule is required.

In the case of Enum, only the Enum sheet must be registered. Otherwise, the sheet name becomes the class name.

In all cases, # is used as a comment (table, column, etc.).

In case of Enum, start :Begin and end point should be :End.

In the case of a table, the first row must be the column name, and the end point must be specified with :End. The second row is the data type, and it is possible to link to the Id column of another table with $.

Korean

Unity, C# ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ณ€ํ™˜๊ธฐ์ž…๋‹ˆ๋‹ค.

๊ทœ์น™์— ๋งž๊ฒŒ ์ž…๋ ฅ๋œ Excel ์‹œํŠธ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

Enum์˜ ๊ฒฝ์šฐ Enum ์‹œํŠธ๋งŒ ๋“ฑ๋กํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์‹œํŠธ ์ด๋ฆ„์ด ํด๋ž˜์Šค ์ด๋ฆ„์ด ๋ฉ๋‹ˆ๋‹ค.

๋ชจ๋“  ๊ฒฝ์šฐ์— #์€ ์ฃผ์„(ํ…Œ์ด๋ธ”, ์—ด ๋“ฑ)์œผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

Enum์˜ ๊ฒฝ์šฐ ์‹œ์ž‘ :Begin, ๋์ ์€ :End์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. (:Begin์€ -b ์ปค๋งจ๋“œ๋ผ์ธ ๋ช…๋ น์œผ๋กœ, :End๋Š” -r (ํ–‰), -z (์ปฌ๋Ÿผ) ์ปค๋งจ๋“œ ๋ผ์ธ ๋ช…๋ น์œผ๋กœ ์žฌ์ง€์ • ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค)

ํ…Œ์ด๋ธ”์˜ ๊ฒฝ์šฐ ์ฒซ ๋ฒˆ์งธ ํ–‰์€ ์—ด ์ด๋ฆ„์ด์–ด์•ผ ํ•˜๋ฉฐ ๋์ ์€ :End๋กœ ์ง€์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. (:End๋Š” -r (ํ–‰), -z (์ปฌ๋Ÿผ) ์ปค๋งจ๋“œ ๋ผ์ธ ๋ช…๋ น์œผ๋กœ ์žฌ์ง€์ • ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค)

๋‘ ๋ฒˆ์งธ ํ–‰์€ ๋ฐ์ดํ„ฐ ํƒ€์ž…์œผ๋กœ $๋กœ ๋‹ค๋ฅธ ํ…Œ์ด๋ธ”์˜ Id ์ปฌ๋Ÿผ๊ณผ ์—ฐ๊ฒฐ์ด ๊ฐ€๋Šฅ ํ•ฉ๋‹ˆ๋‹ค.

Excel Keyword Introduce (English)

Table Name (Sheet Name) Reserved Keyword

# (Comment)

comment or description

! (ignore)

ignore id column check

Data Type Reserved Keyword

# (Comment)

comment or description

! (ignore)

ignore type check (Custom DataType)

% (Percent)

It should be 100 when summing the row values. dataType double

$ (Reference)

Refers to the key of the sheet (table) of the string following $. (Error if associated value does not exist

~ (SubIndex)

cleanup & generate all option.

This is a function to check for duplicates within a table using the same index by placing a secondary index.

ํ…Œ์ด๋ธ”๋ช…(์‹œํŠธ๋ช…) ์˜ˆ์•ฝ์–ด

# ์„ค๋ช…

์ฝ”๋ฉ˜ํŠธ ๋˜๋Š” ์„ค๋ช…

excel_to_dotnet

์‹œํŠธ ๋ณ€ํ™˜์„ ์‹œ๋„ํ•˜์ง€ ์•Š๊ณ  ์ฐธ์กฐ์šฉ ํŽ˜์ด์ง€์—์„œ ์‚ฌ์šฉํ•ด์ฃผ์„ธ์š”.

! ๋ฌด์‹œํ•˜๋‹ค

Id ์ปฌ๋Ÿผ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ ๋ฌด์‹œ

excel_to_dotnet

excel_to_dotnet

์œ„์™€ ๊ฐ™์ด ํ…Œ์ด๋ธ”๋ช… (์‹œํŠธ๋ช…)์— ์‚ฌ์šฉ์‹œ, Id ์ปฌ๋Ÿผ์— ๋Œ€ํ•œ ์ฒดํฌ๋ฅผ ๋ฌด์‹œํ•ฉ๋‹ˆ๋‹ค.

Const{ํ…Œ์ด๋ธ”๋ช…}

์ƒ์ˆ˜ ๊ฐ’์— ๋Œ€ํ•œ ๊ธฐ๋Šฅ์œผ๋กœ, Id ์ปฌ๋Ÿผ์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

excel_to_dotnet

excel_to_dotnet

์œ„์™€ ๊ฐ™์ด Id ์ปฌ๋Ÿผ์ด ์—†์–ด๋„ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ! ํ‚ค์›Œ๋“œ์™€ ๋™์ผํ•œ ๋™์ž‘์ž…๋‹ˆ๋‹ค.

๋ฐ์ดํ„ฐ ํƒ€์ž… ์˜ˆ์•ฝ์–ด

# ์„ค๋ช…

์ฝ”๋ฉ˜ํŠธ ๋˜๋Š” ์„ค๋ช…

excel_to_dotnet

ํ–‰์ด๋‚˜ ์—ด์— ์‚ฌ์šฉ์‹œ, ํ•ด๋‹น ํ–‰์ด๋‚˜ ์—ด์€ ๋ชจ๋‘ ์ฃผ์„์œผ๋กœ ์ธ์‹๋ฉ๋‹ˆ๋‹ค.

! ๋ฌด์‹œํ•˜๋‹ค

primitive type์ด ์•„๋‹Œ, using์„ ํ†ตํ•ด ๊ฐ์ข… ๋‚ด์žฅ ํƒ€์ž… ํ˜น์€ ์™ธ๋ถ€ ๋ฏธ๋ฆฌ ์„ ์–ธ๋œ ํƒ€์ž…์„ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•  ๊ฒฝ์šฐ ์‚ฌ์šฉ (Custom DataType)

excel_to_dotnet

!Vector3 ๊ฐ€ ์˜ˆ์‹œ์ด๋ฉฐ, Vector3๋ฅผ System.Numerics.Vector3๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ ! ํ‚ค์›Œ๋“œ๋ฅผ ์•ž์— ๋ถ™์ž„์œผ๋กœ์จ, ํƒ€์ž… ๊ฒ€์‚ฌ๋ฅผ ๋ฌดํšจํ™” ํ•˜๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.

์ด ๊ธฐ๋Šฅ์€ ๋‚จ๋ฐœ ํ•  ๊ฒฝ์šฐ, ์„œ๋ฒ„๋‚˜ ํด๋ผ์ด์–ธํŠธ ์ปดํŒŒ์ผ ์˜ค๋ฅ˜๋กœ ์ด์–ด์งˆ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ฃผ์˜ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

% ํผ์„ผํŠธ

ํ–‰ ๊ฐ’์„ ํ•ฉ์‚ฐํ•  ๋•Œ 100์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

excel_to_dotnet

ํ–‰์˜ ์ด ํ•ฉ์„ ๊ณ„์‚ฐํ•ด์„œ, 100์ธ์ง€ ์•„๋‹Œ์ง€๋ฅผ ๊ฒ€์‚ฌํ•˜๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.

$ ์ฐธ์กฐ

$ ๋’ค์— ์˜ค๋Š” ๋ฌธ์ž์—ด์˜ ์‹œํŠธ(ํ…Œ์ด๋ธ”)์˜ ํ‚ค๋ฅผ ์ฐธ์กฐํ•ฉ๋‹ˆ๋‹ค. (์—ฐ๊ฒฐ๋œ ๊ฐ’์ด ํ•ด๋‹น ํ…Œ์ด๋ธ”์— ์—†์œผ๋ฉด ์˜ค๋ฅ˜)

excel_to_dotnet

ํŠน์ • ์ปฌ๋Ÿผ์ด, $์ดํ›„์— ์“ฐ์ธ ๋ฌธ์ž์—ด์— ํ•ด๋‹นํ•˜๋Š” ํ…Œ์ด๋ธ”์— ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.

์˜ˆ์‹œ๋Š” Id ์ปฌ๋Ÿผ์— ๋Œ€ํ•ด์„œ ์ฐธ์กฐ ๊ฐ’์œผ๋กœ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ์š”, Id์ปฌ๋Ÿผ์ด ์•„๋‹Œ ์ผ๋ฐ˜ ์ปฌ๋Ÿผ์—์„œ๋„ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

~ ๋ณด์กฐ ์ธ๋ฑ์Šค

๋ชจ๋“  ์˜ต์…˜์„ ์ •๋ฆฌํ•˜๊ณ  ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

๋ณด์กฐ ์ธ๋ฑ์Šค๋ฅผ ๋ฐฐ์น˜ํ•˜์—ฌ ๋™์ผํ•œ ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ…Œ์ด๋ธ” ๋‚ด์—์„œ ์ค‘๋ณต ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.

excel_to_dotnet

์œ„ ์˜ˆ์‹œ๋Š” SubIndex๊ฐ€ ๊ฐ™์€ ๊ฐ’์ธ ํ–‰์— ๋Œ€ํ•ด์„œ, SubKey์— ๋Œ€ํ•ด ์ค‘๋ณต ๊ฒ€์‚ฌ๋ฅผ ํ•ด์ค€๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ํŠน์ • ์Šคํ…Œ์ด์ง€์— ๋Œ€ํ•œ ๋ณด์ƒ์„ ์ง€๊ธ‰ ํ•  ๋•Œ, ๋™์ผํ•œ ์Šคํ…Œ์ด์ง€์—์„œ๋Š” ๋™์ผํ•œ ๋ณด์ƒ์„ ์„ ํƒํ•˜์ง€ ์•Š๊ฒŒ ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

Sample Excel (xlsx)

https://github.com/elky84/ExcelToDotnet/blob/main/ExcelCli/Character.xlsx

add package

dotnet add package ExcelToDotnet

Implment CLI. (link ExcelToDotnet)

Release: https://github.com/elky84/ExcelToDotnet/releases

Reference : https://github.com/elky84/ExcelToDotnet/blob/main/ExcelCli/Program.cs, https://github.com/elky84/ExcelToDotnet/blob/main/ExcelCli

install cli global tool

require dotnet 6 (LTS) or later rumtime (also include rumtime in SDK) (https://dotnet.microsoft.com/en-us/download)

dotnet tool install -g ExcelCli

global tool usage

execute command name is excel2dotnet

use single excel file (-f)

excel2dotnet -f {fileName}

use target directory (-d)

excel2dotnet -d {directory}

use enum generate mode (-e)

excel2dotnet -d {directory} -e

use validation mode (-v)

excel2dotnet d {directory} -v

use nullable mode (-l) => for .NET 6 or later

excel2dotnet d {directory} -l

Execute CLI options (execute build file)

execute file name excel2dotnet instead of ExcelCli

all options

Version History

v1.0.40

  • upgrade Dotnet runtime version to 9.0

v1.0.39

  • changes package structures.
  • remove CodeGenerateExtend, CodeTemplate.

v1.0.38

  • code fix for nullable rules.
  • refactoring Generator.cs

v1.0.37

  • upgrade Dotnet runtime version to 8.0

v1.0.36

  • If it is a List type and contains an Enum, delete the condition that must not be Nullable.

v1.0.35

  • Fix Probability validation error.

v1.0.34

  • Check excel files only generate mode.

v1.0.33

  • Modify DataTableEx's members to be non-nullable

v1.0.32

  • removed string value Trim().

v1.0.31

  • added string value Trim().

v1.0.30

  • The added rule is that the list enum type must be Nullable.

v1.0.29

  • fixed only string column validate id. (changes check all column type)

v1.0.28

  • fixed tableName with ! (remove !) on validation mode.
  • changed check probability sum by column.

v1.0.27

  • added exception log on enum table empty string.

v1.0.26

  • fixed tableName with ! (remove !)

v1.0.25

  • fixed convert !Vector3, !Vector2 bug.

v1.0.24

  • Fixed Validation Failed Exit Code. (0x0 -> 0x4)

v1.0.23

  • Support System.Numerics Vector2 and Vector3

v1.0.22

  • Table EndsWith mark location to StartsWith.

v1.0.21

  • support custom table type. (use with '!')

v1.0.20

  • generate class to partial class

v1.0.19

  • removed ignore mode
  • added wide mode (cleanup & generate all option)
  • fixed sub index, probability functions.

About

Excel sheet (xlsx) to C# code and json. dotnet global cli application.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages