Program.Options.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using CommandLine;
  3. using CommandLine.Text;
  4. namespace excel2json
  5. {
  6. partial class Program
  7. {
  8. /// <summary>
  9. /// 命令行参数定义
  10. /// </summary>
  11. internal sealed class Options
  12. {
  13. public Options()
  14. {
  15. this.HeaderRows = 3;
  16. this.Encoding = "utf8-nobom";
  17. this.Lowcase = false;
  18. this.ExportArray = false;
  19. this.ForceSheetName = false;
  20. }
  21. [Option('e', "excel", Required = true, HelpText = "input excel file path.")]
  22. public string ExcelPath {
  23. get;
  24. set;
  25. }
  26. [Option('j', "json", Required = false, HelpText = "export json file path.")]
  27. public string JsonPath {
  28. get;
  29. set;
  30. }
  31. [Option('p', "csharp", Required = false, HelpText = "export C# data struct code file path.")]
  32. public string CSharpPath {
  33. get;
  34. set;
  35. }
  36. [Option('h', "header", Required = false, DefaultValue = 1, HelpText = "number lines in sheet as header.")]
  37. public int HeaderRows {
  38. get;
  39. set;
  40. }
  41. [Option('c', "encoding", Required = false, DefaultValue = "utf8-nobom", HelpText = "export file encoding.")]
  42. public string Encoding {
  43. get;
  44. set;
  45. }
  46. [Option('l', "lowcase", Required = false, DefaultValue = false, HelpText = "convert filed name to lowcase.")]
  47. public bool Lowcase {
  48. get;
  49. set;
  50. }
  51. [Option('a', "array", Required = false, DefaultValue = false, HelpText = "export as array, otherwise as dict object.")]
  52. public bool ExportArray {
  53. get;
  54. set;
  55. }
  56. [Option('d', "date", Required = false, DefaultValue = "yyyy/MM/dd", HelpText = "Date Format String, example: dd / MM / yyy hh: mm:ss.")]
  57. public string DateFormat {
  58. get;
  59. set;
  60. }
  61. [Option('s', "sheet", Required = false, DefaultValue = false, HelpText = "export with sheet name, even there's only one sheet.")]
  62. public bool ForceSheetName {
  63. get;
  64. set;
  65. }
  66. [Option('x', "exclude_prefix", Required = false, DefaultValue = "", HelpText = "exclude sheet or column start with specified prefix.")]
  67. public string ExcludePrefix {
  68. get;
  69. set;
  70. }
  71. [Option('l', "cell_json", Required = false, DefaultValue = false, HelpText = "convert json string in cell")]
  72. public bool CellJson {
  73. get;
  74. set;
  75. }
  76. }
  77. }
  78. }