Skip to content

Commit 1888908

Browse files
committed
6.1版本更新
1 parent 85a1e38 commit 1888908

14 files changed

+39
-7
lines changed

MySQLToExcel/ExcelOperateHelper.cs

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ public static bool ExportToExcel(string tableName)
139139
if (AppValues.ConfigSheetTabColorIndex > 0)
140140
configWorksheet.Tab.ColorIndex = (XlColorIndex)AppValues.ConfigSheetTabColorIndex;
141141

142+
// 设置表格中所有单元格均为文本格式
143+
configWorksheet.Cells.NumberFormatLocal = "@";
144+
142145
// 写入导出到数据库中的字段名及类型配置
143146
configWorksheet.Cells[1, 1] = AppValues.CONFIG_NAME_EXPORT_DATABASE_TABLE_NAME;
144147
configWorksheet.Cells[2, 1] = tableName;

MySQLToExcel/MySQLToExcel.v12.suo

-8.5 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

XlsxToLua/AppValues.cs

+2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ public class AppValues
147147
public const string CONFIG_NAME_EXPORT_DATABASE_TABLE_NAME = "exportDatabaseTableName";
148148
// 声明某张表格导出到数据库中的说明信息
149149
public const string CONFIG_NAME_EXPORT_DATABASE_TABLE_COMMENT = "exportDatabaseTableComment";
150+
// 声明某张表格导出到数据库中时string型字段中的空白单元格导出为数据库中的NULL
151+
public const string CONFIG_NAME_EXPORT_DATABASE_WRITE_NULL_FOR_EMPTY_STRING = "exportDatabaseWriteNullForEmptyString";
150152
// 声明某张表格导出为lua table时,是否将主键列的值作为table中的元素
151153
public const string CONFIG_NAME_ADD_KEY_TO_LUA_TABLE = "addKeyToLuaTable";
152154

XlsxToLua/TableAnalyzeHelper.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static TableInfo AnalyzeTable(DataTable dt, string tableName, out string
2424
}
2525
else
2626
{
27-
// 解析出第一列,然后检查主键唯一性,如果是string型主键还要检查是否非空、是否符合变量名的规范(只能由英文字母、数字、下划线组成)
27+
// 解析出主键列,然后检查是否非空、唯一,如果是string型主键还要检查是否符合变量名的规范(只能由英文字母、数字、下划线组成)
2828
FieldInfo primaryKeyField = _AnalyzeOneField(dt, tableInfo, 0, null, out curColumnIndex, out errorString);
2929
if (errorString != null)
3030
{
@@ -43,7 +43,8 @@ public static TableInfo AnalyzeTable(DataTable dt, string tableName, out string
4343
errorString = _GetTableAnalyzeErrorString(tableName, 0) + "主键列存在重复错误\n" + errorString;
4444
return null;
4545
}
46-
// string型主键检查是否非空、是否符合变量名的规范
46+
47+
// string型主键检查是否符合变量名的规范
4748
if (primaryKeyColumnType == DataType.String)
4849
{
4950
StringBuilder errorStringBuilder = new StringBuilder();
@@ -57,6 +58,21 @@ public static TableInfo AnalyzeTable(DataTable dt, string tableName, out string
5758
if (!string.IsNullOrEmpty(errorStringBuilder.ToString()))
5859
{
5960
errorString = _GetTableAnalyzeErrorString(tableName, 0) + "string型主键列存在非法数据\n" + errorStringBuilder.ToString();
61+
return null;
62+
}
63+
}
64+
65+
// 非空检查(因为string型检查是否符合变量名规范时以及未声明数值型字段中允许空时,均已对主键列进行过非空检查,这里只需对数据值字段且声明数值型字段中允许空的情况下进行非空检查)
66+
if (AppValues.IsAllowedNullNumber == true && (primaryKeyColumnType == DataType.Int || primaryKeyColumnType == DataType.Long))
67+
{
68+
FieldCheckRule notEmptyCheckRule = new FieldCheckRule();
69+
uniqueCheckRule.CheckType = TableCheckType.NotEmpty;
70+
uniqueCheckRule.CheckRuleString = "notEmpty";
71+
TableCheckHelper.CheckNotEmpty(primaryKeyField, notEmptyCheckRule, out errorString);
72+
if (errorString != null)
73+
{
74+
errorString = _GetTableAnalyzeErrorString(tableName, 0) + "主键列存在非空错误\n" + errorString;
75+
return null;
6076
}
6177
}
6278

@@ -1433,7 +1449,7 @@ private static TableStringFormatDefine _GetTableStringFormatDefine(string dataTy
14331449
Dictionary<string, int> tableKeys = new Dictionary<string, int>();
14341450
for (int i = 0; i < tableElementDefine.Length; ++i)
14351451
{
1436-
TableElementDefine oneTableElementDefine = _GetTablelementDefine(tableElementDefine[i].Trim(), out errorString);
1452+
TableElementDefine oneTableElementDefine = _GetTableElementDefine(tableElementDefine[i].Trim(), out errorString);
14371453
if (errorString != null)
14381454
{
14391455
errorString = string.Format("table类型值声明错误,无法解析{0},", tableElementDefine[i].Trim()) + errorString;
@@ -1481,7 +1497,7 @@ private static TableStringFormatDefine _GetTableStringFormatDefine(string dataTy
14811497
/// <summary>
14821498
/// 将形如type=#1(int)的格式定义字符串转为TableElementDefine定义
14831499
/// </summary>
1484-
private static TableElementDefine _GetTablelementDefine(string tableElementDefine, out string errorString)
1500+
private static TableElementDefine _GetTableElementDefine(string tableElementDefine, out string errorString)
14851501
{
14861502
TableElementDefine elementDefine = new TableElementDefine();
14871503

XlsxToLua/TableExportToMySQLHelper.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ private static bool _InsertData(string tableName, TableInfo tableInfo, out strin
173173

174174
string fieldNameDefineString = Utils.CombineString(fileNames, ", ");
175175

176+
// 用户是否配置该表中string型字段中的空单元格导出至MySQL中为NULL,默认为空字符串
177+
bool isWriteNullForEmptyString = tableInfo.TableConfig != null && tableInfo.TableConfig.ContainsKey(AppValues.CONFIG_NAME_EXPORT_DATABASE_WRITE_NULL_FOR_EMPTY_STRING) && tableInfo.TableConfig[AppValues.CONFIG_NAME_EXPORT_DATABASE_WRITE_NULL_FOR_EMPTY_STRING].Count > 0 && "true".Equals(tableInfo.TableConfig[AppValues.CONFIG_NAME_EXPORT_DATABASE_WRITE_NULL_FOR_EMPTY_STRING][0], StringComparison.CurrentCultureIgnoreCase);
178+
176179
// 逐行生成插入数据的SQL语句中的value定义部分
177180
StringBuilder valueDefineStringBuilder = new StringBuilder();
178181
int count = tableInfo.GetKeyColumnFieldInfo().Data.Count;
@@ -257,11 +260,13 @@ private static bool _InsertData(string tableName, TableInfo tableInfo, out strin
257260
// json型直接向数据库写入原始json字符串,但需要对\进行转义
258261
values.Add(string.Format("'{0}'", fieldInfo.JsonString[i]).Replace("\\", "\\\\"));
259262
}
260-
// 这里需要自行处理向数据库中某些数据类型如datetime的列不允许插入空字符串的情况
263+
// 这里需要自行处理数据库中某些数据类型(如datetime)中不允许插入空字符串的情况,以及用户设置的string型中空单元格导出至数据库的形式
261264
else if (string.IsNullOrEmpty(fieldInfo.Data[i].ToString()))
262265
{
263266
if (fieldInfo.DatabaseFieldType.StartsWith("datetime", StringComparison.CurrentCultureIgnoreCase))
264267
values.Add("NULL");
268+
else if (fieldInfo.DataType == DataType.String && isWriteNullForEmptyString == true)
269+
values.Add("NULL");
265270
else
266271
values.Add(string.Format("'{0}'", fieldInfo.Data[i].ToString()));
267272
}

XlsxToLua/XlsxToLua.v12.suo

0 Bytes
Binary file not shown.

XlsxToLua/bin/Debug/XlsxToLua.exe

512 Bytes
Binary file not shown.

XlsxToLua/bin/Release/XlsxToLua.exe

512 Bytes
Binary file not shown.

更新日志.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
本文件仅列举版本新增功能的大致介绍,详细使用请参考“XlsxToLua工具说明.txt”
2-
辅助工具的说明请参考“辅助工具说明.txt”
1+
本文件仅列举版本新增功能的大致介绍,详细使用请参考PDF版XlsxToLua使用说明”
2+
3+
======= V6.1 2016.11.11 ======
4+
1、Excel表格的config配置表中增加exportDatabaseWriteNullForEmptyString选项,可设置string型字段中的空单元格导出至MySQL数据库时为NULL,而不是默认的空字符串
5+
2、增加显示用OleDb方式读取各张Excel表所用时间的功能
6+
3、读取Excel表时,自动忽略表格末尾所有主键列为空的行
7+
4、float型字段在C#中改为实际用double型存储,float型仅表明是小数类型
8+
5、忽略对Excel自动生成的以~$开头的临时文件的读取
39

410
======= V6.0 2016.10.8 ======
511
1、增加将Excel文件额外导出为csv文件的功能

0 commit comments

Comments
 (0)