using System;
using System.Collections.Generic;
using System.Linq;
namespace Typhoon.Excel2Json.Export
{
public static class Excel2JsonConvert
{
///
/// string[]转int[]
///
public static int[] StringArrayToIntArray(params string[] contents)
{
List result = new List();
foreach (var content in contents)
{
if (string.IsNullOrWhiteSpace(content))
{
break;
}
else
{
result.Add(content.ToInt());
}
}
return result.ToArray();
}
///
/// string[]转long[]
///
public static long[] StringArrayToLongArray(params string[] contents)
{
List result = new List();
foreach (var content in contents)
{
if (string.IsNullOrWhiteSpace(content))
{
break;
}
else
{
result.Add(content.ToLong());
}
}
return result.ToArray();
}
///
/// string[]转float[]
///
public static float[] StringArrayToFloatArray(params string[] contents)
{
List result = new List();
foreach (var content in contents)
{
if (string.IsNullOrWhiteSpace(content))
{
break;
}
else
{
result.Add(content.ToFloat());
}
}
return result.ToArray();
}
///
/// string[]转double[]
///
public static double[] StringArrayToDoubleArray(params string[] contents)
{
List result = new List();
foreach (var content in contents)
{
if (string.IsNullOrWhiteSpace(content))
{
break;
}
else
{
result.Add(content.ToDouble());
}
}
return result.ToArray();
}
///
/// string[]转bool[]
///
public static bool[] StringArrayToBoolArray(params string[] contents)
{
List result = new List();
foreach (var content in contents)
{
if (string.IsNullOrWhiteSpace(content))
{
break;
}
else
{
result.Add(content.ToBool());
}
}
return result.ToArray();
}
///
/// string[]转string[]
///
public static string[] StringArrayToStringArray(params string[] contents)
{
List result = new List();
for (int i = 0; i < contents.Length; i++)
{
var element = contents[i];
if (string.IsNullOrEmpty(element))
{
break;
}
result.Add(element);
}
return result.ToArray();
}
///
/// 字符串转int
///
public static int ToInt(this string str, string error = null)
{
try
{
return int.Parse(str);
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转float
///
public static float ToFloat(this string str, string error = null)
{
try
{
return float.Parse(str);
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转bool
///
public static bool ToBool(this string str, string error = null)
{
try
{
return int.Parse(str) == 1;
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转long
///
public static long ToLong(this string str, string error = null)
{
try
{
return long.Parse(str);
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转double
///
public static double ToDouble(this string str, string error = null)
{
try
{
return double.Parse(str);
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转int[]
///
public static int[] ToIntArray(this string str, string error = null)
{
try
{
if (string.IsNullOrEmpty(str))
{
return new int[0];
}
else
{
var contents = str.Split('|');
var result = new int[contents.Length];
for (int i = 0; i < contents.Length; i++)
{
result[i] = contents[i].ToInt(error);
}
return result;
}
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转float[]
///
public static float[] ToFloatArray(this string str, string error = null)
{
try
{
if (string.IsNullOrEmpty(str))
{
return new float[0];
}
else
{
var contents = str.Split('|');
var result = new float[contents.Length];
for (int i = 0; i < contents.Length; i++)
{
result[i] = contents[i].ToFloat(error);
}
return result;
}
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转double[]
///
public static double[] ToDoubleArray(this string str, string error = null)
{
try
{
if (string.IsNullOrEmpty(str))
{
return new double[0];
}
else
{
var contents = str.Split('|');
var result = new double[contents.Length];
for (int i = 0; i < contents.Length; i++)
{
result[i] = contents[i].ToDouble(error);
}
return result;
}
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转long[]
///
public static long[] ToLongArray(this string str, string error = null)
{
try
{
if (string.IsNullOrEmpty(str))
{
return new long[0];
}
else
{
var contents = str.Split('|');
var result = new long[contents.Length];
for (int i = 0; i < contents.Length; i++)
{
result[i] = contents[i].ToLong(error);
}
return result;
}
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转bool[]
///
public static bool[] ToBoolArray(this string str, string error = null)
{
try
{
if (string.IsNullOrEmpty(str))
{
return new bool[0];
}
else
{
var contents = str.Split('|');
var result = new bool[contents.Length];
for (int i = 0; i < contents.Length; i++)
{
result[i] = contents[i].ToBool(error);
}
return result;
}
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转string[]
///
public static string[] ToStringArray(this string str, string error = null)
{
try
{
if (string.IsNullOrEmpty(str))
{
return new string[0];
}
else
{
var contents = str.Split('|');
var result = new string[contents.Length];
for (int i = 0; i < contents.Length; i++)
{
result[i] = contents[i];
}
return result;
}
}
catch (Exception e)
{
throw;
}
}
///
/// 字符串转int[][]
///
public static int[][] ToIntDyadicArray(this string[] strs)
{
int rangeIndex = strs.Length - 1;
//截取有效范围
for (int i = strs.Length - 1; i >= 0; i--)
{
//遇到第一个非空数组,返回
if (!string.IsNullOrEmpty(strs[i]))
{
rangeIndex = i;
break;
}
}
List result = new List();
for (int i = 0; i <= rangeIndex; i++)
{
var content = strs[i];
result.Add(content.ToIntArray());
}
return result.ToArray();
}
///
/// 字符串转long[][]
///
public static long[][] ToLongDyadicArray(this string[] strs)
{
int rangeIndex = strs.Length - 1;
//截取有效范围
for (int i = strs.Length - 1; i >= 0; i--)
{
//遇到第一个非空数组,返回
if (!string.IsNullOrEmpty(strs[i]))
{
rangeIndex = i;
break;
}
}
List result = new List();
for (int i = 0; i <= rangeIndex; i++)
{
var content = strs[i];
result.Add(content.ToLongArray());
}
return result.ToArray();
}
///
/// 字符串转float[][]
///
public static float[][] ToFloatDyadicArray(this string[] strs)
{
int rangeIndex = strs.Length - 1;
//截取有效范围
for (int i = strs.Length - 1; i >= 0; i--)
{
//遇到第一个非空数组,返回
if (!string.IsNullOrEmpty(strs[i]))
{
rangeIndex = i;
break;
}
}
List result = new List();
for (int i = 0; i <= rangeIndex; i++)
{
var content = strs[i];
result.Add(content.ToFloatArray());
}
return result.ToArray();
}
///
/// 字符串转double[][]
///
public static double[][] ToDoubleDyadicArray(this string[] strs)
{
int rangeIndex = strs.Length - 1;
//截取有效范围
for (int i = strs.Length - 1; i >= 0; i--)
{
//遇到第一个非空数组,返回
if (!string.IsNullOrEmpty(strs[i]))
{
rangeIndex = i;
break;
}
}
List result = new List();
for (int i = 0; i <= rangeIndex; i++)
{
var content = strs[i];
result.Add(content.ToDoubleArray());
}
return result.ToArray();
}
///
/// 字符串转bool[][]
///
public static bool[][] ToBoolDyadicArray(this string[] strs)
{
int rangeIndex = strs.Length - 1;
//截取有效范围
for (int i = strs.Length - 1; i >= 0; i--)
{
//遇到第一个非空数组,返回
if (!string.IsNullOrEmpty(strs[i]))
{
rangeIndex = i;
break;
}
}
List result = new List();
for (int i = 0; i <= rangeIndex; i++)
{
var content = strs[i];
result.Add(content.ToBoolArray());
}
return result.ToArray();
}
///
/// 字符串转string[][]
///
public static string[][] ToStringDyadicArray(this string[] strs)
{
int rangeIndex = strs.Length - 1;
//截取有效范围
for (int i = strs.Length - 1; i >= 0; i--)
{
//遇到第一个非空数组,返回
if (!string.IsNullOrEmpty(strs[i]))
{
rangeIndex = i;
break;
}
}
List result = new List();
for (int i = 0; i <= rangeIndex; i++)
{
var content = strs[i];
result.Add(content.ToStringArray());
}
return result.ToArray();
}
///
/// 是否为空或者空白
///
public static bool IsEmptyOrNull(string[] row, int[] columns)
{
foreach (var column in columns)
{
if (!string.IsNullOrEmpty(row[column]))
{
return false;
}
}
return true;
}
///
/// string[,]转string[][]
///
public static string[][] ToStringDyadicArray(this string[,] strs)
{
List list = new List();
var rows = strs.GetLength(0);
var columns = strs.GetLength(1);
for (int i = 0; i < rows; i++)
{
list.Add(new string[columns]);
for (int j = 0; j < columns; j++)
{
list[i][j] = strs[i, j];
}
}
return list.ToArray();
}
///
/// 构建AllTables实例
///
///
///
public static AllTables ParseToAllTables(Dictionary dic)
{
var result = new AllTables();
$PARSE_TO_ALL_TABLES_METHOD_CONTENT
result.Initialize();
return result;
}
$PARSE_TO_METHOD
$ANALYSIS_KEYS_METHOD
}
}