ExcelTool
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.1169
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExcelTool", "ExcelTool\ExcelTool.csproj", "{60E9C71E-CAEA-402E-B00E-9F3F8D537F7F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{60E9C71E-CAEA-402E-B00E-9F3F8D537F7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{60E9C71E-CAEA-402E-B00E-9F3F8D537F7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{60E9C71E-CAEA-402E-B00E-9F3F8D537F7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{60E9C71E-CAEA-402E-B00E-9F3F8D537F7F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {753CA035-3D1E-49A1-BE7F-ADC7B7292D54}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
|
||||
namespace ExcelTool
|
||||
{
|
||||
/// <summary>
|
||||
/// 控制台帮助类
|
||||
/// </summary>
|
||||
public static class ConsoleHelper
|
||||
{
|
||||
static void WriteColorLine(string str, ConsoleColor color)
|
||||
{
|
||||
ConsoleColor currentForeColor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = color;
|
||||
Console.WriteLine(str);
|
||||
Console.ForegroundColor = currentForeColor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打印错误信息
|
||||
/// </summary>
|
||||
/// <param name="str">待打印的字符串</param>
|
||||
/// <param name="color">想要打印的颜色</param>
|
||||
public static void WriteErrorLine(this string str, ConsoleColor color = ConsoleColor.Red)
|
||||
{
|
||||
WriteColorLine(str, color);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打印警告信息
|
||||
/// </summary>
|
||||
/// <param name="str">待打印的字符串</param>
|
||||
/// <param name="color">想要打印的颜色</param>
|
||||
public static void WriteWarningLine(this string str, ConsoleColor color = ConsoleColor.Yellow)
|
||||
{
|
||||
WriteColorLine(str, color);
|
||||
}
|
||||
/// <summary>
|
||||
/// 打印正常信息
|
||||
/// </summary>
|
||||
/// <param name="str">待打印的字符串</param>
|
||||
/// <param name="color">想要打印的颜色</param>
|
||||
public static void WriteInfoLine(this string str, ConsoleColor color = ConsoleColor.White)
|
||||
{
|
||||
WriteColorLine(str, color);
|
||||
}
|
||||
/// <summary>
|
||||
/// 打印成功的信息
|
||||
/// </summary>
|
||||
/// <param name="str">待打印的字符串</param>
|
||||
/// <param name="color">想要打印的颜色</param>
|
||||
public static void WriteSuccessLine(this string str, ConsoleColor color = ConsoleColor.Green)
|
||||
{
|
||||
WriteColorLine(str, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,438 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using Spire.Xls;
|
||||
|
||||
namespace ExcelTool
|
||||
{
|
||||
public class CsvHelper
|
||||
{
|
||||
static DataTable CSVHeader(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
|
||||
StreamReader sr = new StreamReader(fs, Encoding.Default);
|
||||
string strLine = "";
|
||||
string[] aryLine;
|
||||
int columnCount = 0;
|
||||
int lineIndex = 0;
|
||||
while ((strLine = sr.ReadLine()) != null)
|
||||
{
|
||||
aryLine = strLine.Replace("\"", "").Replace(" ", "").Split(',');
|
||||
if (lineIndex == 0)
|
||||
{
|
||||
columnCount = aryLine.Length;
|
||||
for (int i = 0; i < columnCount; i++)
|
||||
{
|
||||
int typeIndex = i * 2;
|
||||
int nameIndex = typeIndex + 1;
|
||||
if (nameIndex < columnCount)
|
||||
{
|
||||
DataColumn dc = new DataColumn($"{aryLine[nameIndex]}|{aryLine[typeIndex]}");
|
||||
try
|
||||
{
|
||||
dt.Columns.Add(dc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
sr.Close();
|
||||
fs.Close();
|
||||
sr.Dispose();
|
||||
fs.Dispose();
|
||||
return dt;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static DataTable CSV2DataTable(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
|
||||
StreamReader sr = new StreamReader(fs, Encoding.Default);
|
||||
string strLine = "";
|
||||
string[] aryLine;
|
||||
int columnCount = 0;
|
||||
int lineIndex = 0;
|
||||
while ((strLine = sr.ReadLine()) != null)
|
||||
{
|
||||
aryLine = strLine.Replace("\"", "").Replace(" ", "").Split(',');
|
||||
if (lineIndex == 0)
|
||||
{
|
||||
columnCount = aryLine.Length;
|
||||
for (int i = 0; i < columnCount; i++)
|
||||
{
|
||||
int typeIndex = i * 2;
|
||||
int nameIndex = typeIndex + 1;
|
||||
if (nameIndex < columnCount)
|
||||
{
|
||||
DataColumn dc = new DataColumn($"{aryLine[nameIndex]}|{aryLine[typeIndex]}");
|
||||
try
|
||||
{
|
||||
dt.Columns.Add(dc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
columnCount /= 2;
|
||||
}
|
||||
else if (lineIndex == 1) // 注释行
|
||||
{
|
||||
// 注释行先不读,因为注释行里有,号无法分割
|
||||
}
|
||||
else
|
||||
{
|
||||
//1,gender1,12.8,TRUE,"[0,0,1]","[[0,0,0],[0,1,0],[0,2,0],[0,4,0]]"
|
||||
List<string> strs = new List<string>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
bool flag = false;
|
||||
for (int i = 0; i < strLine.Length; i++)
|
||||
{
|
||||
if (strLine[i] == '"')
|
||||
{
|
||||
flag = !flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flag || (!flag && strLine[i] != ','))
|
||||
{
|
||||
sb.Append(strLine[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
strs.Add(sb.ToString());
|
||||
sb.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sb.Length > 0 || strs.Count < columnCount)
|
||||
{
|
||||
strs.Add(sb.ToString());
|
||||
sb.Clear();
|
||||
}
|
||||
aryLine = strs.ToArray();
|
||||
DataRow dr = dt.NewRow();
|
||||
for (int j = 0; j < columnCount; j++)
|
||||
{
|
||||
dr[j] = aryLine[j];
|
||||
}
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
lineIndex++;
|
||||
}
|
||||
|
||||
sr.Close();
|
||||
fs.Close();
|
||||
sr.Dispose();
|
||||
fs.Dispose();
|
||||
return dt;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GenBinaryData(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(fileName);
|
||||
var csvName = fileInfo.Name.Remove(fileInfo.Name.IndexOf(".csv"));
|
||||
|
||||
//先写入行数,然后没一行的数据一次写入 小写类型、字符串
|
||||
List<Tuple<string, string>> datas = new List<Tuple<string, string>>();
|
||||
var dataTable = CSV2DataTable(fileName);
|
||||
Tuple<string, string> rowCount = new Tuple<string, string>("int", dataTable.Rows.Count.ToString());
|
||||
datas.Add(rowCount);
|
||||
//foreach (var col in dataTable.Columns)
|
||||
//{
|
||||
// ConsoleHelper.WriteInfoLine(col.ToString());
|
||||
//}
|
||||
//for (int i = 0; i < dataTable.Columns.Count; i++)
|
||||
//{
|
||||
// ConsoleHelper.WriteInfoLine(dataTable.Columns[i].ToString());
|
||||
//}
|
||||
foreach (DataRow row in dataTable.Rows)
|
||||
{
|
||||
for (int i = 0; i < dataTable.Columns.Count; i++)
|
||||
{
|
||||
var typeHeader = dataTable.Columns[i].ToString().ToLower();
|
||||
var headers = typeHeader.Split('|');
|
||||
Tuple<string, string> t = new Tuple<string, string>(headers[1], row[i].ToString());
|
||||
datas.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
var binaryFilePath = Path.Combine(fileInfo.DirectoryName, $"{csvName}.bytes");
|
||||
FileManager.WriteBinaryDatasToFile(binaryFilePath, datas);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static string CsvToXlsx(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(fileName);
|
||||
var filePath = fileInfo.DirectoryName;
|
||||
var csvName = fileInfo.Name.Remove(fileInfo.Name.IndexOf(".csv"));
|
||||
|
||||
//加载CSV文件
|
||||
Workbook workbook = new Workbook();
|
||||
workbook.LoadFromFile(fileName, ",", 1, 1);
|
||||
|
||||
//获取第一个工作表
|
||||
Worksheet sheet = workbook.Worksheets[0];
|
||||
|
||||
//访问工作表中使用的范围
|
||||
CellRange usedRange = sheet.AllocatedRange;
|
||||
//当将范围内的数字保存为文本时,忽略错误
|
||||
usedRange.IgnoreErrorOptions = IgnoreErrorType.NumberAsText;
|
||||
//自适应行高、列宽
|
||||
usedRange.AutoFitColumns();
|
||||
usedRange.AutoFitRows();
|
||||
|
||||
var excelPath = Path.Combine(filePath, $"{csvName}.xlsx");
|
||||
//保存文档
|
||||
workbook.SaveToFile(Path.Combine(filePath, $"{csvName}.xlsx"), ExcelVersion.Version2013);
|
||||
return excelPath;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成对应的C#Model类
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GenCSharpModel(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(fileName);
|
||||
var csvName = fileInfo.Name.Remove(fileInfo.Name.IndexOf(".csv"));
|
||||
var dt = CSVHeader(fileName);
|
||||
var headers = dt.Headers();
|
||||
//前面是字段,后面是类型 vector是3个float [1.1,2.2,3.3]
|
||||
//foreach (var header in headers)
|
||||
//{
|
||||
// ConsoleHelper.WriteInfoLine($"{header.Item1}|{header.Item2}");
|
||||
//}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append($"/*\n * auto generated by tools(注意:千万不要手动修改本文件)\n * {csvName}\n */\n");
|
||||
sb.Append("using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Linq;\n\n");
|
||||
sb.Append("[Serializable]\n");
|
||||
sb.Append($"public class {csvName} : IBinarySerializable\n");
|
||||
sb.Append("{\n");
|
||||
foreach (var header in headers)
|
||||
{
|
||||
var type = header.Item2.ToLower();
|
||||
if (type.Equals("vector"))
|
||||
{
|
||||
sb.Append(string.Format("\tpublic List<float> {0}", header.Item1));
|
||||
}
|
||||
else if (type.Equals("list"))
|
||||
{
|
||||
sb.Append(string.Format("\tpublic List<List<float>> {0}", header.Item1));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(string.Format("\tpublic {0} {1}", header.Item2.ToLower(), header.Item1));
|
||||
}
|
||||
sb.Append(" { get; set; }\n");
|
||||
}
|
||||
sb.Append("\n\tpublic void DeSerialize(BinaryReader reader)\n");
|
||||
sb.Append("\t{\n");
|
||||
foreach (var header in headers)
|
||||
{
|
||||
var type = header.Item2.ToLower();
|
||||
var name = header.Item1.ToString();
|
||||
if (type.Equals("int"))
|
||||
{
|
||||
sb.Append($"\t\t{name} = reader.ReadInt32();\n");
|
||||
}
|
||||
else if (type.Equals("bool"))
|
||||
{
|
||||
sb.Append($"\t\t{name} = reader.ReadBoolean();\n");
|
||||
}
|
||||
else if (type.Equals("float"))
|
||||
{
|
||||
sb.Append($"\t\t{name} = reader.ReadSingle();\n");
|
||||
}
|
||||
else if (type.Equals("string"))
|
||||
{
|
||||
sb.Append($"\t\t{name} = reader.ReadString();\n");
|
||||
}
|
||||
else if (type.Equals("vector"))
|
||||
{
|
||||
sb.Append($"\t\tvar {name}Count = reader.ReadInt32();\n");
|
||||
sb.Append($"\t\tif ({name}Count > 0)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{name} = new List<float>();\n");
|
||||
sb.Append($"\t\t\tfor (int i = 0; i < {name}Count; i++)\n");
|
||||
sb.Append("\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\t{name}.Add(reader.ReadSingle());\n");
|
||||
sb.Append("\t\t\t}\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t\telse\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{name} = null;\n");
|
||||
sb.Append("\t\t}\n");
|
||||
}
|
||||
else if (type.Equals("list"))
|
||||
{
|
||||
sb.Append($"\t\tvar {name}Count = reader.ReadInt32();\n");
|
||||
sb.Append($"\t\tif ({name}Count > 0)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{name} = new List<List<float>>();\n");
|
||||
sb.Append($"\t\t\tfor (int i = 0; i < {name}Count; i++)\n");
|
||||
sb.Append("\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\tvar tempList = new List<float>();\n");
|
||||
sb.Append($"\t\t\t\tvar tempListCount = reader.ReadInt32();\n");
|
||||
sb.Append($"\t\t\t\tfor (int j = 0; j < tempListCount; j++)\n");
|
||||
sb.Append("\t\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\t\ttempList.Add(reader.ReadSingle());\n");
|
||||
sb.Append("\t\t\t\t}\n");
|
||||
sb.Append($"\t\t\t\t{name}.Add(tempList);\n");
|
||||
sb.Append("\t\t\t}\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t\telse\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{name} = null;\n");
|
||||
sb.Append("\t\t}\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine($"类型:{type}没有解析 {fileName}处理异常");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sb.Append("\t}\n\n");
|
||||
sb.Append("\tpublic void Serialize(BinaryWriter writer)\n");
|
||||
sb.Append("\t{\n");
|
||||
foreach (var header in headers)
|
||||
{
|
||||
var type = header.Item2.ToLower();
|
||||
var name = header.Item1.ToString();
|
||||
if (type.Equals("int") || type.Equals("bool") || type.Equals("float") || type.Equals("string"))
|
||||
{
|
||||
sb.Append($"\t\twriter.Write({name});\n");
|
||||
}
|
||||
else if (type.Equals("vector"))
|
||||
{
|
||||
sb.Append($"\t\tif ({name} == null || {name}.Count == 0)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append("\t\t\twriter.Write(0);\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t\telse\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\twriter.Write({name}.Count);\n");
|
||||
sb.Append($"\t\t\tfor (int i = 0; i < {name}.Count; i++)\n");
|
||||
sb.Append("\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\twriter.Write({name}[i]);\n");
|
||||
sb.Append("\t\t\t}\n");
|
||||
sb.Append("\t\t}\n");
|
||||
}
|
||||
else if (type.Equals("list"))
|
||||
{
|
||||
sb.Append($"\t\tif ({name} == null || {name}.Count == 0)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append("\t\t\twriter.Write(0);\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t\telse\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\twriter.Write({name}.Count);\n");
|
||||
sb.Append($"\t\t\tfor (int i = 0; i < {name}.Count; i++)\n");
|
||||
sb.Append("\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\twriter.Write({name}[i].Count);\n");
|
||||
sb.Append($"\t\t\t\tfor (int j = 0; j < {name}[i].Count; j++)\n");
|
||||
sb.Append("\t\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\t\twriter.Write({name}[i][j]);\n");
|
||||
sb.Append("\t\t\t\t}\n");
|
||||
sb.Append("\t\t\t}\n");
|
||||
sb.Append("\t\t}\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine($"类型:{type}没有解析 {fileName}处理异常");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sb.Append("\t}\n");
|
||||
sb.Append("}\n");
|
||||
|
||||
sb.Append("\n");
|
||||
sb.Append("[Serializable]\n");
|
||||
sb.Append($"public partial class {csvName}Config : IBinarySerializable\n");
|
||||
sb.Append("{\n");
|
||||
sb.Append($"\tpublic List<{csvName}> {csvName}Infos = new List<{csvName}>();\n");
|
||||
sb.Append($"\tpublic void DeSerialize(BinaryReader reader)\n");
|
||||
sb.Append("\t{\n");
|
||||
sb.Append($"\t\tint count = reader.ReadInt32();\n");
|
||||
sb.Append($"\t\tfor (int i = 0;i < count; i++)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{csvName} tempData = new {csvName}();\n");
|
||||
sb.Append($"\t\t\ttempData.DeSerialize(reader);\n");
|
||||
sb.Append($"\t\t\t{csvName}Infos.Add(tempData);\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t}\n");
|
||||
sb.Append("\n");
|
||||
sb.Append("\tpublic void Serialize(BinaryWriter writer)\n");
|
||||
sb.Append("\t{\n");
|
||||
sb.Append($"\t\twriter.Write({csvName}Infos.Count);\n");
|
||||
sb.Append($"\t\tfor (int i = 0; i < {csvName}Infos.Count; i++)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{csvName}Infos[i].Serialize(writer);\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t}\n\n");
|
||||
sb.Append($"\tpublic IEnumerable<{csvName}> QueryById(int id)\n");
|
||||
sb.Append("\t{\n");
|
||||
sb.Append($"\t\tvar datas = from d in {csvName}Infos\n");
|
||||
sb.Append($"\t\t\t\t\twhere d.Id == id\n");
|
||||
sb.Append($"\t\t\t\t\tselect d;\n");
|
||||
sb.Append("\t\treturn datas;\n");
|
||||
sb.Append("\t}\n");
|
||||
sb.Append("}\n");
|
||||
FileManager.WriteToFile(Path.Combine(fileInfo.DirectoryName, $"{csvName}.cs"), sb.ToString());
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
using NPOI.HSSF.UserModel;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace ExcelTool
|
||||
{
|
||||
public class ExcelHelper
|
||||
{
|
||||
//static DataTable ReadFromExcelFile(string filePath)
|
||||
//{
|
||||
// DataTable dt = new DataTable();
|
||||
// IWorkbook wk = null;
|
||||
// string extension = Path.GetExtension(filePath);
|
||||
// try
|
||||
// {
|
||||
// FileStream fs = File.OpenRead(filePath);
|
||||
// //if (extension.Equals(".xls"))
|
||||
// //{
|
||||
// // //把xls文件中的数据写入wk中
|
||||
// // wk = new HSSFWorkbook(fs);
|
||||
// //}
|
||||
// //else
|
||||
// //{
|
||||
// if (extension.Equals(".xlsx")) //这里只考虑xlsx的情况
|
||||
// //把xlsx文件中的数据写入wk中
|
||||
// wk = new XSSFWorkbook(fs);
|
||||
// //}
|
||||
|
||||
// fs.Close();
|
||||
// fs.Dispose();
|
||||
// ISheet sheet = wk.GetSheetAt(0);
|
||||
// IRow row = sheet.GetRow(0); //读取当前行数据
|
||||
// //LastRowNum 是当前表的总行数-1(注意)
|
||||
// for (int i = 0; i <= sheet.LastRowNum; i++)
|
||||
// {
|
||||
// row = sheet.GetRow(i);
|
||||
// if (row != null)
|
||||
// {
|
||||
// for (int j = 0; j < row.LastCellNum; j++)
|
||||
// {
|
||||
// string value = row.GetCell(j).ToString();
|
||||
// Console.Write(value.ToString() + " ");
|
||||
// }
|
||||
// Console.WriteLine("\n");
|
||||
// }
|
||||
// }
|
||||
// return dt;
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// ConsoleHelper.WriteErrorLine(e.Message);
|
||||
// }
|
||||
//}
|
||||
|
||||
static DataTable ExcelHeader(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
IWorkbook wk = null;
|
||||
string extension = Path.GetExtension(fileName);
|
||||
FileStream fs = File.OpenRead(fileName);
|
||||
if (extension.Equals(".xlsx"))
|
||||
wk = new XSSFWorkbook(fs);
|
||||
ISheet sheet = wk.GetSheetAt(0);
|
||||
IRow row = sheet.GetRow(0); //读取当前第一行的数据
|
||||
for (int j = 0; j < row.LastCellNum; j++)
|
||||
{
|
||||
string value = row.GetCell(j).ToString().Replace(" ", "");
|
||||
var array = value.Split(',');
|
||||
if (array.Length != 2)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine("表格第一行类型定义有异常,不是类型,命名的形式");
|
||||
}
|
||||
else
|
||||
{
|
||||
DataColumn dc = new DataColumn($"{array[1]}|{array[0]}"); //命名|类型
|
||||
dt.Columns.Add(dc);
|
||||
}
|
||||
}
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
return dt;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static DataTable Excel2DataTable(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
IWorkbook wk = null;
|
||||
string extension = Path.GetExtension(fileName);
|
||||
FileStream fs = File.OpenRead(fileName);
|
||||
if (extension.Equals(".xlsx"))
|
||||
wk = new XSSFWorkbook(fs);
|
||||
ISheet sheet = wk.GetSheetAt(0);
|
||||
IRow row = sheet.GetRow(0); //读取当前第一行的数据
|
||||
for (int j = 0; j < row.LastCellNum; j++)
|
||||
{
|
||||
string value = row.GetCell(j).ToString().Replace(" ", "").Replace("\"", "");
|
||||
var array = value.Split(',');
|
||||
if (array.Length != 2)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine("表格第一行类型定义有异常,不是类型,命名的形式");
|
||||
}
|
||||
else
|
||||
{
|
||||
DataColumn dc = new DataColumn($"{array[1]}|{array[0]}"); //命名|类型
|
||||
dt.Columns.Add(dc);
|
||||
}
|
||||
}
|
||||
//跳过注释读取数据
|
||||
for (int i = 2; i <= sheet.LastRowNum; i++)
|
||||
{
|
||||
row = sheet.GetRow(i);
|
||||
DataRow dr = dt.NewRow();
|
||||
for (int j = 0; j < row.LastCellNum; j++)
|
||||
{
|
||||
var cellValue = row.GetCell(j);
|
||||
if (cellValue != null)
|
||||
dr[j] = row.GetCell(j).ToString().Replace(" ", "");
|
||||
else
|
||||
dr[j] = "";
|
||||
}
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
return dt;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GenBinaryData(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(fileName);
|
||||
var excelName = fileInfo.Name.Remove(fileInfo.Name.IndexOf(".xlsx"));
|
||||
|
||||
//先写入行数,然后没一行的数据一次写入 小写类型、字符串
|
||||
List<Tuple<string, string>> datas = new List<Tuple<string, string>>();
|
||||
var dataTable = Excel2DataTable(fileName);
|
||||
Tuple<string, string> rowCount = new Tuple<string, string>("int", dataTable.Rows.Count.ToString());
|
||||
datas.Add(rowCount);
|
||||
foreach (DataRow row in dataTable.Rows)
|
||||
{
|
||||
for (int i = 0; i < dataTable.Columns.Count; i++)
|
||||
{
|
||||
var typeHeader = dataTable.Columns[i].ToString().ToLower();
|
||||
var headers = typeHeader.Split('|');
|
||||
Tuple<string, string> t = new Tuple<string, string>(headers[1], row[i].ToString());
|
||||
datas.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
var binaryFilePath = Path.Combine(fileInfo.DirectoryName, $"{excelName}.bytes");
|
||||
FileManager.WriteBinaryDatasToFile(binaryFilePath, datas);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成对应的C#Model类
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GenCSharpModel(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(fileName);
|
||||
var excelName = fileInfo.Name.Remove(fileInfo.Name.IndexOf(".xlsx"));
|
||||
var dt = ExcelHeader(fileName);
|
||||
var headers = dt.Headers();
|
||||
//前面是字段,后面是类型 vector是3个float [1.1,2.2,3.3]
|
||||
//foreach (var header in headers)
|
||||
//{
|
||||
// ConsoleHelper.WriteInfoLine($"{header.Item1}|{header.Item2}");
|
||||
//}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append($"/*\n * auto generated by tools(注意:千万不要手动修改本文件)\n * {excelName}\n */\n");
|
||||
sb.Append("using System;\nusing System.IO;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Linq;\n\n");
|
||||
sb.Append("[Serializable]\n");
|
||||
sb.Append($"public class {excelName} : IBinarySerializable\n");
|
||||
sb.Append("{\n");
|
||||
foreach (var header in headers)
|
||||
{
|
||||
var type = header.Item2.ToLower();
|
||||
if (type.Equals("vector"))
|
||||
{
|
||||
sb.Append(string.Format("\tpublic List<float> {0}", header.Item1));
|
||||
}
|
||||
else if (type.Equals("list"))
|
||||
{
|
||||
sb.Append(string.Format("\tpublic List<List<float>> {0}", header.Item1));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(string.Format("\tpublic {0} {1}", header.Item2.ToLower(), header.Item1));
|
||||
}
|
||||
sb.Append(" { get; set; }\n");
|
||||
}
|
||||
sb.Append("\n\tpublic void DeSerialize(BinaryReader reader)\n");
|
||||
sb.Append("\t{\n");
|
||||
foreach (var header in headers)
|
||||
{
|
||||
var type = header.Item2.ToLower();
|
||||
var name = header.Item1.ToString();
|
||||
if (type.Equals("int"))
|
||||
{
|
||||
sb.Append($"\t\t{name} = reader.ReadInt32();\n");
|
||||
}
|
||||
else if (type.Equals("bool"))
|
||||
{
|
||||
sb.Append($"\t\t{name} = reader.ReadBoolean();\n");
|
||||
}
|
||||
else if (type.Equals("float"))
|
||||
{
|
||||
sb.Append($"\t\t{name} = reader.ReadSingle();\n");
|
||||
}
|
||||
else if (type.Equals("string"))
|
||||
{
|
||||
sb.Append($"\t\t{name} = reader.ReadString();\n");
|
||||
}
|
||||
else if (type.Equals("vector"))
|
||||
{
|
||||
sb.Append($"\t\tvar {name}Count = reader.ReadInt32();\n");
|
||||
sb.Append($"\t\tif ({name}Count > 0)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{name} = new List<float>();\n");
|
||||
sb.Append($"\t\t\tfor (int i = 0; i < {name}Count; i++)\n");
|
||||
sb.Append("\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\t{name}.Add(reader.ReadSingle());\n");
|
||||
sb.Append("\t\t\t}\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t\telse\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{name} = null;\n");
|
||||
sb.Append("\t\t}\n");
|
||||
}
|
||||
else if (type.Equals("list"))
|
||||
{
|
||||
sb.Append($"\t\tvar {name}Count = reader.ReadInt32();\n");
|
||||
sb.Append($"\t\tif ({name}Count > 0)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{name} = new List<List<float>>();\n");
|
||||
sb.Append($"\t\t\tfor (int i = 0; i < {name}Count; i++)\n");
|
||||
sb.Append("\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\tvar tempList = new List<float>();\n");
|
||||
sb.Append($"\t\t\t\tvar tempListCount = reader.ReadInt32();\n");
|
||||
sb.Append($"\t\t\t\tfor (int j = 0; j < tempListCount; j++)\n");
|
||||
sb.Append("\t\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\t\ttempList.Add(reader.ReadSingle());\n");
|
||||
sb.Append("\t\t\t\t}\n");
|
||||
sb.Append($"\t\t\t\t{name}.Add(tempList);\n");
|
||||
sb.Append("\t\t\t}\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t\telse\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{name} = null;\n");
|
||||
sb.Append("\t\t}\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine($"类型:{type}没有解析 {fileName}处理异常");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sb.Append("\t}\n\n");
|
||||
sb.Append("\tpublic void Serialize(BinaryWriter writer)\n");
|
||||
sb.Append("\t{\n");
|
||||
foreach (var header in headers)
|
||||
{
|
||||
var type = header.Item2.ToLower();
|
||||
var name = header.Item1.ToString();
|
||||
if (type.Equals("int") || type.Equals("bool") || type.Equals("float") || type.Equals("string"))
|
||||
{
|
||||
sb.Append($"\t\twriter.Write({name});\n");
|
||||
}
|
||||
else if (type.Equals("vector"))
|
||||
{
|
||||
sb.Append($"\t\tif ({name} == null || {name}.Count == 0)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append("\t\t\twriter.Write(0);\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t\telse\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\twriter.Write({name}.Count);\n");
|
||||
sb.Append($"\t\t\tfor (int i = 0; i < {name}.Count; i++)\n");
|
||||
sb.Append("\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\twriter.Write({name}[i]);\n");
|
||||
sb.Append("\t\t\t}\n");
|
||||
sb.Append("\t\t}\n");
|
||||
}
|
||||
else if (type.Equals("list"))
|
||||
{
|
||||
sb.Append($"\t\tif ({name} == null || {name}.Count == 0)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append("\t\t\twriter.Write(0);\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t\telse\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\twriter.Write({name}.Count);\n");
|
||||
sb.Append($"\t\t\tfor (int i = 0; i < {name}.Count; i++)\n");
|
||||
sb.Append("\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\twriter.Write({name}[i].Count);\n");
|
||||
sb.Append($"\t\t\t\tfor (int j = 0; j < {name}[i].Count; j++)\n");
|
||||
sb.Append("\t\t\t\t{\n");
|
||||
sb.Append($"\t\t\t\t\twriter.Write({name}[i][j]);\n");
|
||||
sb.Append("\t\t\t\t}\n");
|
||||
sb.Append("\t\t\t}\n");
|
||||
sb.Append("\t\t}\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine($"类型:{type}没有解析 {fileName}处理异常");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
sb.Append("\t}\n");
|
||||
sb.Append("}\n");
|
||||
|
||||
sb.Append("\n");
|
||||
sb.Append("[Serializable]\n");
|
||||
sb.Append($"public partial class {excelName}Config : IBinarySerializable\n");
|
||||
sb.Append("{\n");
|
||||
sb.Append($"\tpublic List<{excelName}> {excelName}Infos = new List<{excelName}>();\n");
|
||||
sb.Append($"\tpublic void DeSerialize(BinaryReader reader)\n");
|
||||
sb.Append("\t{\n");
|
||||
sb.Append($"\t\tint count = reader.ReadInt32();\n");
|
||||
sb.Append($"\t\tfor (int i = 0;i < count; i++)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{excelName} tempData = new {excelName}();\n");
|
||||
sb.Append($"\t\t\ttempData.DeSerialize(reader);\n");
|
||||
sb.Append($"\t\t\t{excelName}Infos.Add(tempData);\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t}\n");
|
||||
sb.Append("\n");
|
||||
sb.Append("\tpublic void Serialize(BinaryWriter writer)\n");
|
||||
sb.Append("\t{\n");
|
||||
sb.Append($"\t\twriter.Write({excelName}Infos.Count);\n");
|
||||
sb.Append($"\t\tfor (int i = 0; i < {excelName}Infos.Count; i++)\n");
|
||||
sb.Append("\t\t{\n");
|
||||
sb.Append($"\t\t\t{excelName}Infos[i].Serialize(writer);\n");
|
||||
sb.Append("\t\t}\n");
|
||||
sb.Append("\t}\n\n");
|
||||
sb.Append($"\tpublic IEnumerable<{excelName}> QueryById(int id)\n");
|
||||
sb.Append("\t{\n");
|
||||
sb.Append($"\t\tvar datas = from d in {excelName}Infos\n");
|
||||
sb.Append($"\t\t\t\t\twhere d.Id == id\n");
|
||||
sb.Append($"\t\t\t\t\tselect d;\n");
|
||||
sb.Append("\t\treturn datas;\n");
|
||||
sb.Append("\t}\n");
|
||||
sb.Append("}\n");
|
||||
FileManager.WriteToFile(Path.Combine(fileInfo.DirectoryName, $"{excelName}.cs"), sb.ToString());
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{60E9C71E-CAEA-402E-B00E-9F3F8D537F7F}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>ExcelTool</RootNamespace>
|
||||
<AssemblyName>ExcelTool</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.Excel.2.1.1\lib\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI, Version=2.1.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.Excel.2.1.1\lib\NPOI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI.OOXML, Version=2.1.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.Excel.2.1.1\lib\NPOI.OOXML.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI.OpenXml4Net, Version=2.1.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.Excel.2.1.1\lib\NPOI.OpenXml4Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NPOI.OpenXmlFormats, Version=2.1.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NPOI.Excel.2.1.1\lib\NPOI.OpenXmlFormats.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Spire.Pdf, Version=8.7.2.0, Culture=neutral, PublicKeyToken=663f351905198cb3, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Spire.XLS.12.7.1\lib\net40\Spire.Pdf.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Spire.XLS, Version=12.7.1.0, Culture=neutral, PublicKeyToken=663f351905198cb3, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Spire.XLS.12.7.1\lib\net40\Spire.XLS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConsoleHelper.cs" />
|
||||
<Compile Include="CsvHelper.cs" />
|
||||
<Compile Include="ExcelHelper.cs" />
|
||||
<Compile Include="Extend.cs" />
|
||||
<Compile Include="FileManager.cs" />
|
||||
<Compile Include="IBinarySerializable.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace ExcelTool
|
||||
{
|
||||
public static class Extend
|
||||
{
|
||||
/// <summary>
|
||||
/// 打印DataTable
|
||||
/// </summary>
|
||||
/// <param name="dataTable"></param>
|
||||
/// <param name="withColumns">是否包含表头</param>
|
||||
public static void ToDebug(this DataTable dataTable, bool withColumns = false)
|
||||
{
|
||||
string columnStr = string.Empty;
|
||||
if (withColumns)
|
||||
{
|
||||
for (int i = 0; i < dataTable.Columns.Count; i++)
|
||||
{
|
||||
columnStr += dataTable.Columns[i] + " ";
|
||||
}
|
||||
ConsoleHelper.WriteInfoLine(columnStr);
|
||||
}
|
||||
for (int i = 0; i < dataTable.Rows.Count; i++)
|
||||
{
|
||||
columnStr = string.Empty;
|
||||
for (int j = 0; j < dataTable.Columns.Count; j++)
|
||||
{
|
||||
columnStr += dataTable.Rows[i][j] + " ";
|
||||
}
|
||||
ConsoleHelper.WriteInfoLine(columnStr);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Tuple<string, string>> Headers(this DataTable dataTable)
|
||||
{
|
||||
List<Tuple<string, string>> headers = new List<Tuple<string, string>>();
|
||||
for (int i = 0; i < dataTable.Columns.Count; i++)
|
||||
{
|
||||
var pairs = dataTable.Columns[i].ToString().Split('|');
|
||||
headers.Add(new Tuple<string, string>(pairs[0], pairs[1]));
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace ExcelTool
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件操作类
|
||||
/// </summary>
|
||||
public class FileManager
|
||||
{
|
||||
public static bool CreateDir(string dirPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dirPath))
|
||||
return false;
|
||||
if (Directory.Exists(dirPath))
|
||||
{
|
||||
Directory.Delete(dirPath, true);
|
||||
}
|
||||
Directory.CreateDirectory(dirPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将数据写入二进制文件
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="data">继承自IBinarySerialize的数据</param>
|
||||
public static bool WriteBinaryDataToFile(string filePath, IBinarySerializable data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
return false;
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
using (var bw = new BinaryWriter(fileStream))
|
||||
{
|
||||
data.Serialize(bw);
|
||||
bw.Flush();
|
||||
bw.Close();
|
||||
}
|
||||
fileStream.Close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将数据写入二进制文件
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="datas">类型(小写)和value的字符串键值对</param>
|
||||
/// <returns></returns>
|
||||
public static bool WriteBinaryDatasToFile(string filePath, List<Tuple<string, string>> datas)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
return false;
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
using (var fileStream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
using (var bw = new BinaryWriter(fileStream))
|
||||
{
|
||||
foreach (var data in datas)
|
||||
{
|
||||
if (data.Item1.Equals("int"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(data.Item2))
|
||||
{
|
||||
bw.Write(Convert.ToInt32(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write(Convert.ToInt32(data.Item2));
|
||||
}
|
||||
}
|
||||
else if (data.Item1.Equals("bool"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(data.Item2))
|
||||
{
|
||||
bw.Write(Convert.ToBoolean(false));
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write(Convert.ToBoolean(data.Item2));
|
||||
}
|
||||
}
|
||||
else if (data.Item1.Equals("float"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(data.Item2))
|
||||
{
|
||||
bw.Write(Convert.ToSingle(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write(Convert.ToSingle(data.Item2));
|
||||
}
|
||||
}
|
||||
else if (data.Item1.Equals("double"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(data.Item2))
|
||||
{
|
||||
bw.Write(Convert.ToDouble(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write(Convert.ToDouble(data.Item2));
|
||||
}
|
||||
}
|
||||
else if (data.Item1.Equals("string"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(data.Item2))
|
||||
{
|
||||
bw.Write("");
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write(data.Item2.ToString());
|
||||
}
|
||||
}
|
||||
else if (data.Item1.Equals("long"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(data.Item2))
|
||||
{
|
||||
bw.Write(Convert.ToInt64(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
bw.Write(Convert.ToInt64(data.Item2));
|
||||
}
|
||||
}
|
||||
else if (data.Item1.Equals("vector"))
|
||||
{
|
||||
//[1.2,3.4,5.6]
|
||||
var str = data.Item2.ToString();
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
bw.Write(Convert.ToInt32(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
str = str.Replace("]", "").Replace("[", "");
|
||||
var numStrs = str.Split(',');
|
||||
int vectorCount = 3;
|
||||
bw.Write(vectorCount);
|
||||
for (int i = 0; i < vectorCount; i++)
|
||||
{
|
||||
float v = Convert.ToSingle(numStrs[i]);
|
||||
bw.Write(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (data.Item1.Equals("list"))
|
||||
{
|
||||
//[[1.2,3.4,5.6],[2.2,3.4,5.6],[3.2,3.4,5.6]]
|
||||
string str = data.Item2.ToString();
|
||||
if (string.IsNullOrEmpty(str))
|
||||
{
|
||||
bw.Write(Convert.ToInt32(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
str = str.Replace("]", "").Replace("[", "");
|
||||
var numStrs = str.Split(',');
|
||||
bw.Write(Convert.ToInt32(numStrs.Length / 3));
|
||||
for (int i = 0; i < numStrs.Length; i++)
|
||||
{
|
||||
if (i % 3 == 0)
|
||||
bw.Write(Convert.ToInt32(3));
|
||||
bw.Write(Convert.ToSingle(numStrs[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine($"写入二进制文件,数据类型{data.Item1}没有适配");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bw.Flush();
|
||||
bw.Close();
|
||||
}
|
||||
fileStream.Close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine(ex.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从内存流中读取二进制
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ReadBinaryDataFromBytes(byte[] bytes, ref IBinarySerializable data)
|
||||
{
|
||||
if (bytes == null)
|
||||
return false;
|
||||
using (var memoryStream = new MemoryStream(bytes))
|
||||
{
|
||||
using (var br = new BinaryReader(memoryStream))
|
||||
{
|
||||
data.DeSerialize(br);
|
||||
br.Close();
|
||||
}
|
||||
memoryStream.Close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取二进制文件
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ReadBinaryDataFromFile(string filePath, ref IBinarySerializable data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (var fileStream = new FileStream(filePath, FileMode.Open))
|
||||
{
|
||||
using (var br = new BinaryReader(fileStream))
|
||||
{
|
||||
data.DeSerialize(br);
|
||||
br.Close();
|
||||
}
|
||||
fileStream.Close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool WriteBytesToFile(string filePath, byte[] data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
return false;
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
var file = new FileInfo(filePath);
|
||||
using (Stream sw = file.Create())
|
||||
{
|
||||
sw.Write(data, 0, data.Length);
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串写入文件
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public static bool WriteToFile(string filePath, string context)
|
||||
{
|
||||
return WriteToFile(filePath, context, Encoding.Default);
|
||||
}
|
||||
|
||||
public static bool WriteToFile(string filePath, string context, Encoding encoding)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
return false;
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
var data = encoding.GetBytes(context);
|
||||
fs.Write(data, 0, data.Length);
|
||||
fs.Flush();
|
||||
fs.Close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按行读取
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static string ReadAllByLine(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
using (StreamReader sr = new StreamReader(path, Encoding.Default))
|
||||
{
|
||||
string line;
|
||||
while ((line = sr.ReadLine()) != null)
|
||||
{
|
||||
sb.AppendLine(line);
|
||||
}
|
||||
sr.Close();
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static byte[] ReadAllBytes(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return File.ReadAllBytes(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改文件内容
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="normalStr"></param>
|
||||
/// <param name="newStr"></param>
|
||||
public static void ReplaceContent(string path, string normalStr, string newStr)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
string strContent = File.ReadAllText(path);
|
||||
strContent = strContent.Replace(normalStr, newStr);
|
||||
File.WriteAllText(path, strContent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量修改文件内容
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="newStr"></param>
|
||||
/// <param name="normalStrs"></param>
|
||||
public static void ReplaceContent(string path, string newStr, params string[] normalStrs)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
string strContent = File.ReadAllText(path);
|
||||
for (int i = 0; i < normalStrs.Length; i++)
|
||||
{
|
||||
strContent = strContent.Replace(normalStrs[i], newStr);
|
||||
}
|
||||
File.WriteAllText(path, strContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using System.IO;
|
||||
|
||||
public interface IBinarySerializable
|
||||
{
|
||||
void DeSerialize(BinaryReader reader);
|
||||
void Serialize(BinaryWriter writer);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using Spire.Xls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace ExcelTool
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string path = AppDomain.CurrentDomain.BaseDirectory;
|
||||
if (args != null && args.Length >= 1)
|
||||
{
|
||||
path = args[0]; //第一个是路径
|
||||
}
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
||||
var csvs = dirInfo.GetFiles("*.csv", SearchOption.AllDirectories);
|
||||
var excels = dirInfo.GetFiles("*.xlsx", SearchOption.AllDirectories);
|
||||
if ((csvs == null || csvs.Length <= 0) && (excels == null || excels.Length <= 0))
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine("当前exe目录或者目标目录没有csv文件或者excels文件,请重新设置目录");
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleHelper.WriteSuccessLine("==========================================================");
|
||||
ConsoleHelper.WriteSuccessLine("== 根据csv/xlsx生成模板代码和二进制文件工具 ==");
|
||||
ConsoleHelper.WriteSuccessLine("== 说明:将exe放在csv/xlsx目录中或者exe或者传入csv根目录 ==");
|
||||
ConsoleHelper.WriteSuccessLine("==========================================================");
|
||||
|
||||
List<string> genExcels = new List<string>();
|
||||
foreach (var csv in csvs)
|
||||
{
|
||||
//生成对应的xlsx文件
|
||||
var tempPath = CsvHelper.CsvToXlsx(csv.FullName);
|
||||
if (string.IsNullOrEmpty(tempPath))
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine($"csv:{csv.FullName}生成xlsx文件出错");
|
||||
}
|
||||
else
|
||||
{
|
||||
genExcels.Add(tempPath);
|
||||
}
|
||||
}
|
||||
excels = dirInfo.GetFiles("*.xlsx", SearchOption.AllDirectories);
|
||||
|
||||
//读取
|
||||
foreach (var file in excels)
|
||||
{
|
||||
//生成CS文件
|
||||
bool res = ExcelHelper.GenCSharpModel(file.FullName);
|
||||
if (res)
|
||||
{
|
||||
ConsoleHelper.WriteSuccessLine($"{file.Name}CS模板生成成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine($"{file.Name}CS模板生成失败");
|
||||
}
|
||||
|
||||
//生成二进制文件,如果list或者vector数据为空则写入0,要根据类型来读取csv的字段数据强转成对应的数据类型然后写入
|
||||
res = ExcelHelper.GenBinaryData(file.FullName);
|
||||
if (res)
|
||||
{
|
||||
ConsoleHelper.WriteSuccessLine($"{file.Name}二进制数据生成成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine($"{file.Name}二进制数据生成失败");
|
||||
}
|
||||
}
|
||||
|
||||
//删除生成的excels
|
||||
for (int i = genExcels.Count - 1; i >= 0; i--)
|
||||
{
|
||||
File.Delete(genExcels[i]);
|
||||
}
|
||||
Console.Read();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("ExcelTool")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ExcelTool")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("60e9c71e-caea-402e-b00e-9f3f8d537f7f")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||
// 方法是按如下所示使用“*”: :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
</configuration>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* auto generated by tools(注意:千万不要手动修改本文件)
|
||||
* avatarguideTest
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
[Serializable]
|
||||
public class avatarguideTest : IBinarySerializable
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string gender { get; set; }
|
||||
public float age { get; set; }
|
||||
public bool bValue { get; set; }
|
||||
public List<float> vector { get; set; }
|
||||
public List<List<float>> Grid { get; set; }
|
||||
|
||||
public void DeSerialize(BinaryReader reader)
|
||||
{
|
||||
Id = reader.ReadInt32();
|
||||
gender = reader.ReadString();
|
||||
age = reader.ReadSingle();
|
||||
bValue = reader.ReadBoolean();
|
||||
var vectorCount = reader.ReadInt32();
|
||||
if (vectorCount > 0)
|
||||
{
|
||||
vector = new List<float>();
|
||||
for (int i = 0; i < vectorCount; i++)
|
||||
{
|
||||
vector.Add(reader.ReadSingle());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vector = null;
|
||||
}
|
||||
var GridCount = reader.ReadInt32();
|
||||
if (GridCount > 0)
|
||||
{
|
||||
Grid = new List<List<float>>();
|
||||
for (int i = 0; i < GridCount; i++)
|
||||
{
|
||||
var tempList = new List<float>();
|
||||
var tempListCount = reader.ReadInt32();
|
||||
for (int j = 0; j < tempListCount; j++)
|
||||
{
|
||||
tempList.Add(reader.ReadSingle());
|
||||
}
|
||||
Grid.Add(tempList);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Grid = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(Id);
|
||||
writer.Write(gender);
|
||||
writer.Write(age);
|
||||
writer.Write(bValue);
|
||||
if (vector == null || vector.Count == 0)
|
||||
{
|
||||
writer.Write(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(vector.Count);
|
||||
for (int i = 0; i < vector.Count; i++)
|
||||
{
|
||||
writer.Write(vector[i]);
|
||||
}
|
||||
}
|
||||
if (Grid == null || Grid.Count == 0)
|
||||
{
|
||||
writer.Write(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(Grid.Count);
|
||||
for (int i = 0; i < Grid.Count; i++)
|
||||
{
|
||||
writer.Write(Grid[i].Count);
|
||||
for (int j = 0; j < Grid[i].Count; j++)
|
||||
{
|
||||
writer.Write(Grid[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public partial class avatarguideTestConfig : IBinarySerializable
|
||||
{
|
||||
public List<avatarguideTest> avatarguideTestInfos = new List<avatarguideTest>();
|
||||
public void DeSerialize(BinaryReader reader)
|
||||
{
|
||||
int count = reader.ReadInt32();
|
||||
for (int i = 0;i < count; i++)
|
||||
{
|
||||
avatarguideTest tempData = new avatarguideTest();
|
||||
tempData.DeSerialize(reader);
|
||||
avatarguideTestInfos.Add(tempData);
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(avatarguideTestInfos.Count);
|
||||
for (int i = 0; i < avatarguideTestInfos.Count; i++)
|
||||
{
|
||||
avatarguideTestInfos[i].Serialize(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<avatarguideTest> QueryById(int id)
|
||||
{
|
||||
var datas = from d in avatarguideTestInfos
|
||||
where d.Id == id
|
||||
select d;
|
||||
return datas;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* auto generated by tools(注意:千万不要手动修改本文件)
|
||||
* official_room
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
[Serializable]
|
||||
public class official_room : IBinarySerializable
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string RoomOwner { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string RoomName { get; set; }
|
||||
public string RoomBriefly { get; set; }
|
||||
public string RoomDetails { get; set; }
|
||||
public string BgPathId { get; set; }
|
||||
public string ScenesId { get; set; }
|
||||
public string Address { get; set; }
|
||||
public int Recommend { get; set; }
|
||||
public int SubLine { get; set; }
|
||||
public int IsCanPackage { get; set; }
|
||||
public int IsMute { get; set; }
|
||||
public List<float> BirthPosition { get; set; }
|
||||
public List<float> Offset { get; set; }
|
||||
|
||||
public void DeSerialize(BinaryReader reader)
|
||||
{
|
||||
Id = reader.ReadInt32();
|
||||
RoomOwner = reader.ReadString();
|
||||
Notes = reader.ReadString();
|
||||
RoomName = reader.ReadString();
|
||||
RoomBriefly = reader.ReadString();
|
||||
RoomDetails = reader.ReadString();
|
||||
BgPathId = reader.ReadString();
|
||||
ScenesId = reader.ReadString();
|
||||
Address = reader.ReadString();
|
||||
Recommend = reader.ReadInt32();
|
||||
SubLine = reader.ReadInt32();
|
||||
IsCanPackage = reader.ReadInt32();
|
||||
IsMute = reader.ReadInt32();
|
||||
var BirthPositionCount = reader.ReadInt32();
|
||||
if (BirthPositionCount > 0)
|
||||
{
|
||||
BirthPosition = new List<float>();
|
||||
for (int i = 0; i < BirthPositionCount; i++)
|
||||
{
|
||||
BirthPosition.Add(reader.ReadSingle());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BirthPosition = null;
|
||||
}
|
||||
var OffsetCount = reader.ReadInt32();
|
||||
if (OffsetCount > 0)
|
||||
{
|
||||
Offset = new List<float>();
|
||||
for (int i = 0; i < OffsetCount; i++)
|
||||
{
|
||||
Offset.Add(reader.ReadSingle());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Offset = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(Id);
|
||||
writer.Write(RoomOwner);
|
||||
writer.Write(Notes);
|
||||
writer.Write(RoomName);
|
||||
writer.Write(RoomBriefly);
|
||||
writer.Write(RoomDetails);
|
||||
writer.Write(BgPathId);
|
||||
writer.Write(ScenesId);
|
||||
writer.Write(Address);
|
||||
writer.Write(Recommend);
|
||||
writer.Write(SubLine);
|
||||
writer.Write(IsCanPackage);
|
||||
writer.Write(IsMute);
|
||||
if (BirthPosition == null || BirthPosition.Count == 0)
|
||||
{
|
||||
writer.Write(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(BirthPosition.Count);
|
||||
for (int i = 0; i < BirthPosition.Count; i++)
|
||||
{
|
||||
writer.Write(BirthPosition[i]);
|
||||
}
|
||||
}
|
||||
if (Offset == null || Offset.Count == 0)
|
||||
{
|
||||
writer.Write(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(Offset.Count);
|
||||
for (int i = 0; i < Offset.Count; i++)
|
||||
{
|
||||
writer.Write(Offset[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public partial class official_roomConfig : IBinarySerializable
|
||||
{
|
||||
public List<official_room> official_roomInfos = new List<official_room>();
|
||||
public void DeSerialize(BinaryReader reader)
|
||||
{
|
||||
int count = reader.ReadInt32();
|
||||
for (int i = 0;i < count; i++)
|
||||
{
|
||||
official_room tempData = new official_room();
|
||||
tempData.DeSerialize(reader);
|
||||
official_roomInfos.Add(tempData);
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(official_roomInfos.Count);
|
||||
for (int i = 0; i < official_roomInfos.Count; i++)
|
||||
{
|
||||
official_roomInfos[i].Serialize(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<official_room> QueryById(int id)
|
||||
{
|
||||
var datas = from d in official_roomInfos
|
||||
where d.Id == id
|
||||
select d;
|
||||
return datas;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
"int,Id","string,RoomOwner","string,Notes","string,RoomName","string,RoomBriefly","string,RoomDetails","string,BgPathId","string,ScenesId","string,Address","int,Recommend","int,SubLine","int,IsCanPackage","int,IsMute","Vector,BirthPosition","Vector,Offset"
|
||||
序号,,注释(产品用来自己备注的),默认名称(该场景的默认显示的名称),默认场景简述(该场景默认显示的简要描述信息,显示在官方房间入口上),场景详情(该场景的详细描述信息,显示在详情页中),背景图(对应显示在详情界面上的图片pathID或路径,希望能支持填写为一个表,即填多张,以支持轮播显示),对应场景ID(对应场景注册表中的场景ID),对应地图地址(对应高德上的地图地址,填对应点的经纬度,是否要同时把POI点名称填上,由程序确认),初始推荐排序(房间生成时的推荐优先级,确定初始显示位置,数字越低,优先级越高,后续会随着房间推荐算法变化),分线启用人数(达到多少人启用分线,不填或为0为不分线),客人是否可使用背包(在该房间中,客人不可以使用背包),进入默认静音,出生点坐标,
|
||||
1,TcjF8790673,福州峰会1号会场,福州峰会1号会场,可与三坊七巷主会场进行虚实互动的线上会场,一年一度的福州数字峰会在三坊七巷再度召开,通过分会场可实现虚实结合的体验,不仅可以在线上参与盛会,还会以数字分身的形式前往现实会场,与现场的用户进行互动,"{[""path1"":"""",""path2"":""""]}",1001,"{
|
||||
""lat"":119.299236,
|
||||
""lon"":26.081825,
|
||||
""name"":""刘齐衔故居""
|
||||
}",0,100,0,1,"[-497.225,17.536,-107.682]","[0,0,0]"
|
||||
2,TcjF8790673,101会议室,101会议室,101会议室,101会议室,"{[""path1"":"""",""path2"":""""]}",1002,"{
|
||||
""lat"":119.299236,
|
||||
""lon"":26.081825,
|
||||
""name"":""刘齐衔故居""
|
||||
}",0,100,0,1,"[-14243.48, 15.88, -3211.575]","[-14241.71,17.02,-3207.24]"
|
||||
3,TcjF8790673,外滩广场 ,外滩广场,上海市重要的地标场所之一,看万国建筑,观美丽江景。,外滩是上海市上海重要的地标之一,它全长1.5公里,南起延安东路,北至苏州河上的外白渡桥,东面即黄浦江,西面是旧上海金融、外贸机构的集中地。外滩沿路坐拥二十多幢风格各异的历史建筑,有折衷主义的,也有文艺复兴式的,还有早期现代式的,故而被誉为“万国建筑博览群”。自上海开埠后,外滩就开始成为了上海乃至中国的金融及贸易中心[1],也被称为“东方华尔街”。,"{[""path1"":"""",""path2"":""""]}",1003,"{
|
||||
""lat"":121.492156,
|
||||
""lon"":31.233462,
|
||||
""name"":""外滩""
|
||||
}",1,100,0,1,"[-1632.7,-869,0]","[0,0,0]"
|
||||
|
Binary file not shown.
@@ -0,0 +1 @@
|
||||
e8f99ac55eff58f68485e1025b84f8bc7ff8a4e9
|
||||
@@ -0,0 +1,18 @@
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\ExcelTool.exe.config
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\ExcelTool.exe
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\ExcelTool.pdb
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\Spire.Pdf.dll
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\Spire.XLS.dll
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\Microsoft.mshtml.dll
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\Spire.Pdf.xml
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\Spire.XLS.xml
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\obj\Debug\ExcelTool.csprojAssemblyReference.cache
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\obj\Debug\ExcelTool.csproj.CoreCompileInputs.cache
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\obj\Debug\ExcelTool.csproj.CopyComplete
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\obj\Debug\ExcelTool.exe
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\obj\Debug\ExcelTool.pdb
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\ICSharpCode.SharpZipLib.dll
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\NPOI.dll
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\NPOI.OOXML.dll
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\NPOI.OpenXml4Net.dll
|
||||
C:\Users\d00605132\Desktop\ExcelTool\ExcelTool\bin\Debug\NPOI.OpenXmlFormats.dll
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NPOI.Excel" version="2.1.1" targetFramework="net461" />
|
||||
<package id="Spire.XLS" version="12.7.1" targetFramework="net461" />
|
||||
</packages>
|
||||
@@ -0,0 +1,192 @@
|
||||
# ExcelTool
|
||||
|
||||
通用CSV/Excel打表工具
|
||||
#### 前言
|
||||
目前项目中用的csv转json工具,会带来严重的gc性能问题,例如启动加载慢,影响帧率等问题,转成的json数据,我们需要手动写对应的解析模板代码,所以针对以上问题,本通用打表工具应运而生,用二进制数据替代json数据会比较好的解决性能问题,而且能够自动生成对应的模板代码,节省了写重复代码的时间,而且二进制数据比json文件大小更小。
|
||||
|
||||
#### 功能
|
||||
* 支持csv和Excel打表导出模板和
|
||||
* 生成对应的数据模板代码
|
||||
* 生成二进制文件
|
||||
* 自动将文件拷贝到对应的工程目录
|
||||
* 二进制数据读取
|
||||
* 字段不配置会使用默认数值
|
||||
|
||||
#### 目前支持的字段
|
||||
* 常规的字段,例如int,float,string,bool,long
|
||||
* 支持自定义字段 vector,例如[1,2,3]
|
||||
* 支持自定义字段 list,其实是vector数组,例如[[1,2,3],[2,3,4],[4,5,6]]
|
||||
|
||||
#### 效果
|
||||

|
||||
|
||||

|
||||
相比较json,二进制文件大小只有其1/4
|
||||
|
||||
##### 生成的自动化模板代码
|
||||
```
|
||||
/*
|
||||
* auto generated by tools(注意:千万不要手动修改本文件)
|
||||
* avatarguideTest
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[Serializable]
|
||||
public class avatarguideTest : IBinarySerializable
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string gender { get; set; }
|
||||
public float age { get; set; }
|
||||
public bool bValue { get; set; }
|
||||
public List<float> vector { get; set; }
|
||||
public List<List<float>> Grid { get; set; }
|
||||
|
||||
public void DeSerialize(BinaryReader reader)
|
||||
{
|
||||
Id = reader.ReadInt32();
|
||||
gender = reader.ReadString();
|
||||
age = reader.ReadSingle();
|
||||
bValue = reader.ReadBoolean();
|
||||
var vectorCount = reader.ReadInt32();
|
||||
if (vectorCount > 0)
|
||||
{
|
||||
vector = new List<float>();
|
||||
for (int i = 0; i < vectorCount; i++)
|
||||
{
|
||||
vector.Add(reader.ReadSingle());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vector = null;
|
||||
}
|
||||
var GridCount = reader.ReadInt32();
|
||||
if (GridCount > 0)
|
||||
{
|
||||
Grid = new List<List<float>>();
|
||||
for (int i = 0; i < GridCount; i++)
|
||||
{
|
||||
var tempList = new List<float>();
|
||||
var tempListCount = reader.ReadInt32();
|
||||
for (int j = 0; j < tempListCount; j++)
|
||||
{
|
||||
tempList.Add(reader.ReadSingle());
|
||||
}
|
||||
Grid.Add(tempList);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Grid = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(Id);
|
||||
writer.Write(gender);
|
||||
writer.Write(age);
|
||||
writer.Write(bValue);
|
||||
if (vector == null || vector.Count == 0)
|
||||
{
|
||||
writer.Write(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(vector.Count);
|
||||
for (int i = 0; i < vector.Count; i++)
|
||||
{
|
||||
writer.Write(vector[i]);
|
||||
}
|
||||
}
|
||||
if (Grid == null || Grid.Count == 0)
|
||||
{
|
||||
writer.Write(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(Grid.Count);
|
||||
for (int i = 0; i < Grid.Count; i++)
|
||||
{
|
||||
writer.Write(Grid[i].Count);
|
||||
for (int j = 0; j < Grid[i].Count; j++)
|
||||
{
|
||||
writer.Write(Grid[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class avatarguideTestList : IBinarySerializable
|
||||
{
|
||||
public List<avatarguideTest> avatarguideTestInfos = new List<avatarguideTest>();
|
||||
public void DeSerialize(BinaryReader reader)
|
||||
{
|
||||
int count = reader.ReadInt32();
|
||||
for (int i = 0;i < count; i++)
|
||||
{
|
||||
avatarguideTest tempData = new avatarguideTest();
|
||||
tempData.DeSerialize(reader);
|
||||
avatarguideTestInfos.Add(tempData);
|
||||
}
|
||||
}
|
||||
|
||||
public void Serialize(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(avatarguideTestInfos.Count);
|
||||
for (int i = 0; i < avatarguideTestInfos.Count; i++)
|
||||
{
|
||||
avatarguideTestInfos[i].Serialize(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
#### 使用案例
|
||||
##### 解析二进制文件
|
||||
```
|
||||
IBinarySerializable newavList = new avatarguideTestList();
|
||||
var readOK = FileManager.ReadBinaryDataFromFile(Path.Combine(path, "avatarguideTest.dat"), ref newavList);
|
||||
if (readOK)
|
||||
{
|
||||
ConsoleHelper.WriteInfoLine(newavList.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleHelper.WriteErrorLine("读取失败");
|
||||
}
|
||||
```
|
||||

|
||||
|
||||
#### 自动化拷贝批处理
|
||||
```
|
||||
@echo off
|
||||
|
||||
echo "开始拷贝jsons"
|
||||
for %%i in (*.dat) do (
|
||||
echo begin copy... %%i
|
||||
copy /y %%~nxi ..\..\hola_unity\Assets\Resources\Config\%%~nxi
|
||||
echo copy complate ... %%i
|
||||
)
|
||||
echo "拷贝完成"
|
||||
|
||||
pause
|
||||
```
|
||||
|
||||
#### 带扩展的功能
|
||||
目前还不是最理想的状态,还有很多可以扩展完善的功能,如下:
|
||||
|
||||
* 支持生成各种类型的文件,例如json、xml、proto等
|
||||
* 支持生成各种语法的模板代码
|
||||
* 支持Excel数据配置规范性检测,例如手误配置不符合规范导致加载异常,例如大小写逗号(肉眼容易忽略),或者空格等等
|
||||
* 支持Excel字段客户端服务器可选项
|
||||
* 支持更多自定义数据类型扩展
|
||||
|
||||
#### 代码仓
|
||||
https://codehub-g.huawei.com/d00605132/CsvTool
|
||||
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
+71642
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+39685
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+72339
File diff suppressed because it is too large
Load Diff
+39956
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
+71582
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+39912
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+71582
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+39912
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+71680
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+39695
File diff suppressed because it is too large
Load Diff
+124
@@ -0,0 +1,124 @@
|
||||
License Agreement
|
||||
|
||||
BY INSTALLING, DOWNLOADING, COPYING OR OTHERWISE USING THE PRODUCT, YOU AGREE TO BE BOUND BY THE TERMS OF THIS EULA. IF YOU DO NOT AGREE TO THE TERMS OF THIS EULA, DO NOT INSTALL, DOWNLOAD, COPY OR USE THE PRODUCT.
|
||||
1. IMPORTANT NOTICE.
|
||||
|
||||
YOU SHOULD READ THE FOLLOWING TERMS AND CONDITIONS CAREFULLY BEFORE YOU DOWNLOAD, INSTALL OR USE E-ICEBLUE'S COMPONENT AND RELATED DOCUMENTATION (THE "LICENSED SOFTWARE") DISTRIBUTED UNDER THE TRADEMARK OF COMPONENT AND/OR E-ICEBLUE. BY INSTALLING OR USING THE LICENSED SOFTWARE, YOU AGREE TO BE BOUND BY THIS LICENSE AGREEMENT, AND ITS TERMS SHALL BE BINDING WITH RESPECT TO YOUR USE OF THE LICENSED SOFTWARE. IF YOU DO NOT AGREE TO THE FOLLOWING TERMS AND CONDITIONS, DO NOT INSTALL OR USE THE SOFTWARE.
|
||||
2. DEFINITIONS.
|
||||
|
||||
A. "e-iceblue" means e-iceblue Corporation
|
||||
B. "You" and "Your" mean the party purchasing a license to use the Licensed Software under the terms of this agreement.
|
||||
C. "Application Programming Interface or API" means a publicly accessible interface defining the ways by which an application program may request services from libraries and/or software.
|
||||
D. "Licensed Software" means compiled Objects, Modules, License Key and any and all updates thereto, together with all associated documentation provided by e-iceblue or its authorized resellers.
|
||||
E. "License Key" means a unique code provided by e-iceblue or its authorized resellers which identifies You, as well as the license type, and which unlocks or enables certain features of the Licensed Software.
|
||||
F. "Application" or "Your Application" means a software application that You develop which incorporates all or parts of the Licensed Software.
|
||||
G. "Evaluation Trial Period" means a specified period of time during which You may temporarily use the Licensed Software for evaluation purposes only.
|
||||
3. LICENSE GRANT.
|
||||
|
||||
The Cumulative License granted to You by e-iceblue is a combination of the Base License Grant, described in section (3A) below, which is common to every Licensed Software title covered by this agreement, and one or more supplemental License Grant which covers the specific product obtained by You from e-iceblue or its authorized resellers.
|
||||
Four basic types of supplemental License Grants are described in sections (3B): Evaluation License, Developer License, Developer OEM License, Site Enterprise License, Site OEM License.
|
||||
These five basic types are hereby further defined and/or restricted as to the number of developers, servers, geography locations and distribution method(s), depending on the specific product(s) being licensed by You.
|
||||
The precise combination of the Base License Grant and one or more supplemental License Grant(s) obtained by You is identified by e-iceblue at the time of purchase or most recent upgrade.
|
||||
3A. BASE LICENSE GRANT.
|
||||
|
||||
In consideration of Your payment of applicable license fees and/or Your acceptance of the terms of this Agreement, e-iceblue hereby grants to You certain nonexclusive and nontransferable rights limited by the terms of this Agreement.
|
||||
The Licensed Software is licensed (not sold) to You, for use strictly under the terms of this Agreement, and e-iceblue reserves all rights not expressly granted to You herein. If You upgrade the Licensed Software to a higher-numbered version thereof or to a comparable E-iceblue product, this license is terminated and Your rights shall be limited to the license associated with the upgraded product or version.
|
||||
In addition, You acknowledge that the Licensed Software may contain certain third party software components which are distributed under the terms of their own licenses.
|
||||
3B. EVALUATION LICENSE.
|
||||
|
||||
In order to facilitate an efficient evaluation process of the Licensed Software by developers, e-iceblue may, at its discretion, provide specially designed, temporary License Key(s) that are encoded with an embedded expiration date.
|
||||
The License granted in conjunction with such License Key(s) is considered temporary, and multiple developers may use it for the sole purpose of evaluating the Licensed Software during a specific Evaluation Trial Period. Licensed Evaluation Trial Software contains mechanisms that inhibit its ability to function at a later date.
|
||||
It is Your responsibility to ensure that the Applications You create do not contain Licensed Evaluation Trial Software and that their ability to function at a later date is not inhibited or diminished.
|
||||
3C. DEVELOPER LICENSE.
|
||||
|
||||
The following terms and conditions contained in this section (3C) apply to You ONLY if at the time of original purchase or most recent upgrade, the License granted to You by E-iceblue was defined as "Developer License".
|
||||
The specific license level selected by you at the time of purchase or most recent upgrade determines whether the license applies to (1) a single named developer, or (2) a team of named developers, for example a Developer Team, or (3) a single site (facility or campus) whereby an unlimited number of developers located within said site (facility or campus) may be allowed access to the Licensed Software.
|
||||
|
||||
You are hereby granted a nonexclusive, royalty-free license to integrate the Licensed Software into Your Applications and to distribute such Licensed Software in connection with said Applications, provided that
|
||||
(a) said Applications do not in any way compete with the Licensed Software, or provide substantially the same functionality as the Licensed Software, or expose the functionality of the Licensed Software through a programmable interface;
|
||||
(b) each of Your Applications developed using Licensed Software is substantially larger, more complex, and contains a significantly wider range of functions as compared to the Licensed Software;
|
||||
(c) each of Your Applications developed using Licensed Software is designed for end users, rather than for developers who would be able to build other software that would compete with the Licensed Software, and
|
||||
(d) You do not permit further distribution of the Licensed Software by Your end users.
|
||||
|
||||
You may embed the License Keys in the Applications You distribute, provided that the following conditions are met:
|
||||
(a) each such Application must be marked with a prominent copyright notice bearing Your name as declared by You during purchase of the License;
|
||||
(b) the License Key may not be embedded in any such Application or distributed in any other manner that makes the License Key visible to the end user, and
|
||||
(c) each such Application must include the following comment in its source code within close proximity to each copy of an embedded License Key: "This application utilizes a licensed copy of e-iceblue software, copyright (c) 2004-2018, which is the property of e-iceblue Corporation, www.e-iceblue.com. All rights are reserved by e-iceblue.
|
||||
Use of any objects outside of the context of this application is a violation of United States and international copyright laws and other applicable laws."
|
||||
|
||||
For each License Key provided to You by e-iceblue, depending on the specific license level selected by you at the time of purchase or most recent upgrade, You are granted a nonexclusive License to make the Licensed Software and/or the License Key(s) available either to the specified number of Your named developers or to an unlimited number of Your developers located at a single site (facility or campus) as indicated by e-iceblue and further explained below.
|
||||
Should either the number of named developers or the number of sites with access to the Licensed Software and/or the License Key(s) ever exceed the number indicated at the time of original purchase or most recent upgrade, You agree to inform E-iceblue of such change and to upgrade Your License accordingly by paying an upgrade fee to e-iceblue in a timely manner.
|
||||
|
||||
One Developer Subscription authorizes One developer to utilize our product to create unlimited number of applications which can be deployed at only One geography location within your organization. This type of license supports one server or multiple servers in the same place, which is/are used to host your web application.
|
||||
One Developer OEM Subscription authorizes One developer to create any number of applications using our product which can be deployed at Unlimited geography locations. This type of license allows royalty-free distribution.
|
||||
One Site Enterprise Subscription entitles up to 10 developers in the register enterprise to create an unlimited number of custom applications/service using our product. It allows deployment of any number of custom applications at up to 10 geography locations.
|
||||
One Site Enterprise OEM Subscription authorizes up to 50 developers in the register organization to create an unlimited number of custom applications using our product. It allows royalty-free deployment of any number of custom applications to Unlimited geography locations.
|
||||
|
||||
4. RESTRICTIONS ON USE AND TRANSFER.
|
||||
|
||||
You may not sublicense, rent, lease, assign or otherwise transfer the Licensed Software or any of Your rights thereto, either in whole or in part, to anyone else, except that You may, after obtaining written permission from e-iceblue, permanently transfer the Licensed Software in its entirety, provided You retain no copies of the Licensed Software and the transferee agrees to the terms and conditions of this Agreement.
|
||||
Use of the Licensed Software with a License Key obtained from a source other than e-iceblue or its authorized resellers is expressly and strictly forbidden. e-iceblue reserves the right to take any and all actions that e-iceblue, in its sole discretion, deems necessary to protect against, monitor and control the use of the Licensed Software with illegal License Keys.
|
||||
You agree to ensure that anyone who uses any portion of the Licensed Software provided to You complies with the terms and conditions of this Agreement.
|
||||
5. INTELLECTUAL PROPERTY RIGHTS.
|
||||
|
||||
You acknowledge that the Licensed Software contains copyrighted material, trade secrets, trademarks and other proprietary material of e-iceblue ("Confidential Information"), and is protected under United States and international copyright law and other applicable laws.
|
||||
You may not engage in any unauthorized use or disclosure of any Confidential Information. You agree that the source code of the Licensed Software is confidential and proprietary to e-iceblue. Accordingly, You may not copy the Licensed Software, or decompile, disassemble, reverse engineer or create a derivative work based upon the Licensed Software, or authorize anyone else to do so.
|
||||
You must reproduce and maintain all copyright notices that are contained in the Licensed Software on any copy thereof that You make or use.
|
||||
6. TERM AND TERMINATION.
|
||||
|
||||
Except as otherwise provided in this Agreement, depending on the specific license level selected by you at the time of purchase or most recent upgrade, the term of the license granted herein is either perpetual, or alternatively the license is periodic, valid for a specific period of time, such as a month or a year.
|
||||
The license becomes effective when You install or use the Licensed Software. You may terminate this license at any time by destroying any and all copies of the Licensed Software or by returning all such copies to e-iceblue.
|
||||
This Agreement and the associated license for the Licensed Software will terminate automatically and without provision of notice by e-iceblue if You fail to comply with any of the terms or conditions of this Agreement or if You cease permanent use of the Licensed Software, for whatever reason.
|
||||
Upon termination of this Agreement for any reason, You agree that You will destroy all copies of the Licensed Software or return all such copies to e-iceblue. In addition to this sentence and the previous sentence, Sections 4, 5 and 7-13 shall survive any termination of this Agreement.
|
||||
7. LIMITED WARRANTY.
|
||||
|
||||
e-iceblue warrants that the Licensed Software will perform substantially in accordance with its accompanying documentation, when operated in the execution environment specified in such documentation, for the warranty period ending thirty (30) days following the date on which You first install or first use the Licensed Software.
|
||||
This limited warranty is void if failure of the Licensed Software to conform to such warranty is caused in whole or in part by
|
||||
(a) any defect in any hardware or other equipment used with the Licensed Software;
|
||||
(b) any failure of any hardware or any other equipment used with the Licensed Software to function in accordance with applicable manufacturer's specifications for such items;
|
||||
(c) any alteration, modification or enhancement of the Licensed Software by You or anyone other than e-iceblue;
|
||||
(d) any failure by You or anyone else to follow e-iceblue's instructions with respect to proper use of the Licensed Software; or
|
||||
(e) improper use, abuse, accident, neglect or negligence on the part of You or anyone other than e-iceblue.
|
||||
e-iceblue will not be obligated to honor the limited warranty or provide any remedy thereunder unless the Licensed Software is returned to e-iceblue along with the original dated receipt.
|
||||
Any replacement Licensed Software will be warranted for thirty (30) days following the date on which e-iceblue provides it to You.
|
||||
|
||||
EXCEPT AS OTHERWISE SET FORTH IN THIS AGREEMENT, THE LICENSED SOFTWARE IS PROVIDED TO YOU "AS IS", AND E-ICEBLUE MAKES NO EXPRESS OR IMPLIED WARRANTIES WHATSOEVER WITH RESPECT TO ITS FUNCTIONALITY, CONDITION, PERFORMANCE, OPERABILITY OR USE.
|
||||
WITHOUT LIMITING THE FOREGOING, E-ICEBLUE DISCLAIMS ALL IMPLIED WARRANTIES INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR FREEDOM FROM INFRINGEMENT.
|
||||
SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSIONS MAY NOT APPLY TO YOU.
|
||||
THIS LIMITED WARRANTY GIVES YOU SPECIFIC LEGAL RIGHTS, AND YOU MAY ALSO HAVE OTHER RIGHTS THAT VARY FROM ONE JURISDICTION TO ANOTHER.
|
||||
8. LIMITATIONS OF LIABILITY.
|
||||
|
||||
YOUR SOLE AND EXCLUSIVE REMEDY FOR ANY BREACH OF THE FOREGOING LIMITED WARRANTY SHALL BE, AT E-ICEBLUE'S OPTION, EITHER (A) REPAIR OR REPLACEMENT OF THE LICENSED SOFTWARE SO THAT IT CONFORMS TO THE FOREGOING LIMITED WARRANTY, OR (B) REFUND OF THE FEE THAT YOU PAID TO LICENSE THE LICENSED SOFTWARE.
|
||||
IN NO EVENT SHALL E-ICEBLUE BE LIABLE FOR ANY DAMAGES OF ANY TYPE, WHETHER DIRECT OR INDIRECT, CONSEQUENTIAL, INCIDENTAL OR SPECIAL DAMAGES, INCLUDING WITHOUT LIMITATION, LOST REVENUES, LOST PROFITS, LOSSES RESULTING FROM BUSINESS INTERRUPTION OR LOSS OF DATA, REGARDLESS OF THE FORM OF ACTION OR LEGAL THEORY UNDER WHICH SUCH LIABILITY MAY BE ASSERTED, EVEN IF E-ICEBLUE HAS BEEN ADVISED OF THE POSSIBILITY OR LIKELIHOOD OF SUCH DAMAGES.
|
||||
E-ICEBLUE SHALL HAVE NO LIABILITY WITH RESPECT TO ANY DATA THAT IS READ, ACCESSED, STORED OR PROCESSED WITH THE LICENSED SOFTWARE, OR FOR THE COSTS OF RECOVERING ANY SUCH DATA.
|
||||
IN NO EVENT SHALL E-ICEBLUE'S MAXIMUM AGGREGATE LIABILITY UNDER THIS AGREEMENT EXCEED THE TOTAL FEES PAID OR PAYABLE BY YOU TO LICENSE THE LICENSED SOFTWARE.
|
||||
SOME JURISDICTIONS DO NOT ALLOW THE LIMITATION OR EXCLUSION OF LIABILITY FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE ABOVE LIMITATION OR EXCLUSION MAY NOT APPLY TO YOU.
|
||||
9. INDEMNIFICATION.
|
||||
|
||||
You agree to defend, indemnify, and hold E-iceblue and all of its employees, agents, representatives, directors, officers, partners, shareholders, attorneys, predecessors, successors, and assigns harmless from and against any and all claims, proceedings, damages, injuries, liabilities, losses, costs, and expenses (including reasonable attorneys' fees and litigation expenses), relating to or arising from Your use of the Licensed Software, or any breach of this Agreement, except to the extent such claim relates to or arises from a violation by e-iceblue of any third party copyright, trademark, trade secret or other intellectual property right.
|
||||
10. EXPORT.
|
||||
|
||||
You agree that You will not export or transmit the Licensed Software or any Applications, directly or indirectly, to any restricted countries or in any manner that would violate United States laws and regulations as shall from time to time govern the license and delivery of technology abroad by persons subject to the jurisdiction of the United States government, including the Export Administration Act of 1979, as amended, and any applicable laws or regulations issued thereafter.
|
||||
11. U.S. GOVERNMENT RESTRICTED RIGHTS.
|
||||
|
||||
If You are licensing the Licensed Software on behalf of the U.S. Government or any of its agencies ("Government"), the use, duplication, reproduction, release, modification, disclosure or transfer of the Licensed Software by the Government is subject to restricted rights in accordance with Federal Acquisition Regulation ("FAR") 12.212 for civilian agencies and Defense Federal Acquisition Regulation Supplement ("DFARS") 227.7202 for military agencies.
|
||||
The Licensed Software is commercial. Use of the Licensed Software by the Government is further restricted in accordance with the terms and conditions of this Agreement.
|
||||
12. MISCELLANEOUS.
|
||||
|
||||
If any provision of this Agreement is held to be invalid or unenforceable under any circumstances, its application in any other circumstances and the remaining provisions of this Agreement shall not be affected.
|
||||
No waiver of any right under this Agreement shall be effective unless given in writing by an authorized representative of e-iceblue.
|
||||
No waiver by e-iceblue of any right shall be deemed to be a waiver of any other right of e-iceblue arising under this Agreement.
|
||||
This Agreement is solely between You and e-iceblue and shall not be construed to create any third party beneficiary rights in any other individual, partnership, corporation or other entity.
|
||||
This Agreement shall be governed by and interpreted in accordance with the laws of the State of New York, without regard to its provisions governing conflicts of law.
|
||||
Any and all disputes between You and e-iceblue pertaining to this Agreement shall be submitted to one arbitrator in binding arbitration within ten miles of New York City, New York in accordance with the Commercial Rules of the American Arbitration Association ("AAA").
|
||||
The arbitrator shall be experienced in computer consulting, the development of custom software, the sale of packaged software, or related services.
|
||||
If You and e-iceblue do not agree on an arbitrator within sixty (60) days of the institution of the arbitration, the arbitrator shall be chose by AAA.
|
||||
Evidence and argument may be presented in person or by telephone, fax, postal mail, electronic mail, and other methods of communication approved by the arbitrator.
|
||||
The prevailing party in such proceeding shall be entitled to recover its actually incurred costs, including reasonable attorney's fees, arbitration and court costs.
|
||||
All hearings shall be held and a written arbitration award issued within one-hundred eighty (180) days of the date on which the arbitrator is appointed.
|
||||
Judgment on the award shall be final and binding and may be entered in any court of competent jurisdiction.
|
||||
13. ENTIRE AGREEMENT.
|
||||
|
||||
YOU AGREE THAT THIS AGREEMENT IS THE COMPLETE AND EXCLUSIVE STATEMENT OF THE AGREEMENT BETWEEN YOU AND E-ICEBLUE, AND THAT IT SUPERSEDES ANY PROPOSALS OR PRIOR AGREEMENTS, ORAL OR WRITTEN, AND ANY OTHER COMMUNICATIONS RELATING TO THE LICENSED SOFTWARE AND THE SUBJECT MATTER HEREOF.
|
||||
E-ICEBLUE SHALL NOT BE BOUND BY ANY PROVISION OF ANY PURCHASE ORDER, RECEIPT, ACCEPTANCE, CONFIRMATION, CORRESPONDENCE OR OTHERWISE, OR BY ANY AGREEMENT BETWEEN YOU AND ANY OTHER PARTY, UNLESS E-ICEBLUE SPECIFICALLY AGREES TO SUCH PROVISION IN WRITING IN A FORM OF A LEGAL CONTRACT, DATED AND SIGNED BY YOU AND BY E-ICEBLUE'S OFFICER OR AUTHORIZED EMPLOYEE.
|
||||
NO VENDOR, DISTRIBUTOR, PROVIDER, RESELLER, OEM, SALES REPRESENTATIVE, OR OTHER PERSON IS AUTHORIZED TO MODIFY THIS AGREEMENT OR TO MAKE ANY WARRANTY, REPRESENTATION OR PROMISE REGARDING THE LICENSED SOFTWARE WHICH IS DIFFERENT FROM THOSE SET FORTH IN THIS AGREEMENT.
|
||||
Reference in New Issue
Block a user