Skip to content

Commit

Permalink
升级至 4.8,修复参数值错误 fix neil3d#61
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonic853 committed Jul 11, 2024
1 parent 6bf9572 commit 4ce00f2
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 4,321 deletions.
18 changes: 9 additions & 9 deletions Program.Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,55 +38,55 @@ public string CSharpPath {
set;
}

[Option('h', "header", Required = false, DefaultValue = 1, HelpText = "number lines in sheet as header.")]
[Option('h', "header", Required = false, Default = 1, HelpText = "number lines in sheet as header.")]
public int HeaderRows {
get;
set;
}

[Option('c', "encoding", Required = false, DefaultValue = "utf8-nobom", HelpText = "export file encoding.")]
[Option('c', "encoding", Required = false, Default = "utf8-nobom", HelpText = "export file encoding.")]
public string Encoding {
get;
set;
}

[Option('l', "lowcase", Required = false, DefaultValue = false, HelpText = "convert filed name to lowcase.")]
[Option('l', "lowcase", Required = false, Default = false, HelpText = "convert filed name to lowcase.")]
public bool Lowcase {
get;
set;
}

[Option('a', "array", Required = false, DefaultValue = false, HelpText = "export as array, otherwise as dict object.")]
[Option('a', "array", Required = false, Default = false, HelpText = "export as array, otherwise as dict object.")]
public bool ExportArray {
get;
set;
}

[Option('d', "date", Required = false, DefaultValue = "yyyy/MM/dd", HelpText = "Date Format String, example: dd / MM / yyy hh: mm:ss.")]
[Option('d', "date", Required = false, Default = "yyyy/MM/dd", HelpText = "Date Format String, example: dd / MM / yyy hh: mm:ss.")]
public string DateFormat {
get;
set;
}

[Option('s', "sheet", Required = false, DefaultValue = false, HelpText = "export with sheet name, even there's only one sheet.")]
[Option('s', "sheet", Required = false, Default = false, HelpText = "export with sheet name, even there's only one sheet.")]
public bool ForceSheetName {
get;
set;
}

[Option('x', "exclude_prefix", Required = false, DefaultValue = "", HelpText = "exclude sheet or column start with specified prefix.")]
[Option('x', "exclude_prefix", Required = false, Default = "", HelpText = "exclude sheet or column start with specified prefix.")]
public string ExcludePrefix {
get;
set;
}

[Option('l', "cell_json", Required = false, DefaultValue = false, HelpText = "convert json string in cell")]
[Option('j', "cell_json", Required = false, Default = false, HelpText = "convert json string in cell")]
public bool CellJson {
get;
set;
}

[Option('l', "all_string", Required = false, DefaultValue = false, HelpText = "all string")]
[Option('r', "all_string", Required = false, Default = false, HelpText = "all string")]
public bool AllString
{
get;
Expand Down
69 changes: 48 additions & 21 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Data;
using System.Text;
using System.Windows.Forms;
using CommandLine;


namespace excel2json
Expand Down Expand Up @@ -32,30 +33,56 @@ static void Main(string[] args)
//-- COMMAND LINE MODE -------------------------------------------------

//-- 分析命令行参数
var options = new Options();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);
// var options = new Options();
// var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-1)))
{
//-- 执行导出操作
try
// if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-1)))
// {
// //-- 执行导出操作
// try
// {
// DateTime startTime = DateTime.Now;
// Run(options);
// //-- 程序计时
// DateTime endTime = DateTime.Now;
// TimeSpan dur = endTime - startTime;
// Console.WriteLine(
// string.Format("[{0}]:\tConversion complete in [{1}ms].",
// Path.GetFileName(options.ExcelPath),
// dur.TotalMilliseconds)
// );
// }
// catch (Exception exp)
// {
// Console.WriteLine("Error: " + exp.Message);
// }
// }
var parser = new Parser(with => with.HelpWriter = Console.Error);

parser.ParseArguments<Options>(args)
.WithParsed(options =>
{
DateTime startTime = DateTime.Now;
Run(options);
//-- 程序计时
DateTime endTime = DateTime.Now;
TimeSpan dur = endTime - startTime;
Console.WriteLine(
string.Format("[{0}]:\tConversion complete in [{1}ms].",
Path.GetFileName(options.ExcelPath),
dur.TotalMilliseconds)
);
}
catch (Exception exp)
//-- 执行导出操作
try
{
var startTime = DateTime.Now;
Run(options);
//-- 程序计时
var endTime = DateTime.Now;
var dur = endTime - startTime;
Console.WriteLine($"[{Path.GetFileName(options.ExcelPath)}]:\tConversion complete in [{dur.TotalMilliseconds}ms].");
}
catch (Exception exp)
{
Console.WriteLine($"Error: {exp.Message}");
}
})
.WithNotParsed(errors =>
{
Console.WriteLine("Error: " + exp.Message);
}
}
// 处理解析错误
Environment.Exit(-1);
});

}// end of else
}

Expand Down
42 changes: 21 additions & 21 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
51 changes: 35 additions & 16 deletions excel2json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>excel2json</RootNamespace>
<AssemblyName>excel2json</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -39,28 +41,44 @@
<ApplicationIcon>Resources\excel2json.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
<Reference Include="CommandLine, Version=2.9.1.0, Culture=neutral, PublicKeyToken=5a870481e358d379, processorArchitecture=MSIL">
<HintPath>packages\CommandLineParser.2.9.1\lib\net461\CommandLine.dll</HintPath>
</Reference>
<Reference Include="ExcelDataReader, Version=3.6.0.0, Culture=neutral, PublicKeyToken=93517dbe6a4012fa, processorArchitecture=MSIL">
<HintPath>packages\ExcelDataReader.3.6.0\lib\net45\ExcelDataReader.dll</HintPath>
<Reference Include="ExcelDataReader, Version=3.7.0.0, Culture=neutral, PublicKeyToken=93517dbe6a4012fa, processorArchitecture=MSIL">
<HintPath>packages\ExcelDataReader.3.7.0\lib\net462\ExcelDataReader.dll</HintPath>
</Reference>
<Reference Include="ExcelDataReader.DataSet, Version=3.6.0.0, Culture=neutral, PublicKeyToken=93517dbe6a4012fa, processorArchitecture=MSIL">
<HintPath>packages\ExcelDataReader.DataSet.3.6.0\lib\net35\ExcelDataReader.DataSet.dll</HintPath>
<Reference Include="ExcelDataReader.DataSet, Version=3.7.0.0, Culture=neutral, PublicKeyToken=93517dbe6a4012fa, processorArchitecture=MSIL">
<HintPath>packages\ExcelDataReader.DataSet.3.7.0\lib\net462\ExcelDataReader.DataSet.dll</HintPath>
</Reference>
<Reference Include="FastColoredTextBox, Version=2.16.24.0, Culture=neutral, PublicKeyToken=fb8aa12b994ef61b, processorArchitecture=MSIL">
<HintPath>packages\FCTB.2.16.24\lib\FastColoredTextBox.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib, Version=1.2.0.246, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>packages\SharpZipLib.1.2.0\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
<Reference Include="ICSharpCode.SharpZipLib, Version=1.4.2.13, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>packages\SharpZipLib.1.4.2\lib\netstandard2.0\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down Expand Up @@ -89,6 +107,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="ChangeLog.md" />
<None Include="Resources\App.config" />
<None Include="LICENSE" />
Expand Down Expand Up @@ -119,11 +138,11 @@
<None Include="Resources\about.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading

0 comments on commit 4ce00f2

Please sign in to comment.