ImportCommon
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks; namespace WLYD.Utility.File
{
public class ImportCommon
{ public static string TitleRequiredValidate(PropertyInfo[] properties, Dictionary<int, string> titleDic)
{
foreach (var property in properties)
{
var attr = (DisplayAttribute)property.GetCustomAttribute(typeof(DisplayAttribute), false);
if (attr != null && !string.IsNullOrEmpty(attr.Name))
{
if (!titleDic.Values.Any(h => h == attr.Name))
{
return attr.Name;
}
}
}
return null;
} public static object StringToPropertyValue(PropertyInfo property, string src)
{
object obj = null;
switch (property.PropertyType.Name)
{
case "String":
return src;
case "Decimal":
return decimal.Parse(src);
case "Int32":
return int.Parse(src);
case "DateTime":
return DateTime.Parse(src);
case "Boolean":
return bool.Parse(src);
}
return obj;
} public static string GetPropertyByExcelName(PropertyInfo[] properties, string excelTitleName)
{
foreach (var property in properties)
{
var attr = (DisplayAttribute)property.GetCustomAttribute(typeof(DisplayAttribute), false);
if (attr != null && attr.Name == excelTitleName)
{
return property.Name;
}
}
return null;
} /// <summary>
/// 获取流编码
/// </summary>
/// <param name="fs"></param>
/// <returns></returns>
public static Encoding GetStreamEncode(Stream fs)
{
System.IO.BinaryReader br = new System.IO.BinaryReader(fs); Byte[] buffer = br.ReadBytes(2); if (buffer[0] >= 0xEF) { if (buffer[0] == 0xEF && buffer[1] == 0xBB) { return System.Text.Encoding.UTF8; } else if (buffer[0] == 0xFE && buffer[1] == 0xFF) { return System.Text.Encoding.BigEndianUnicode; } else if (buffer[0] == 0xFF && buffer[1] == 0xFE) { return System.Text.Encoding.Unicode; } else { return System.Text.Encoding.Default; } } else { return System.Text.Encoding.Default; }
}
}
}
ImportCommon的更多相关文章
随机推荐
- iOS 插件制作
概述 我们平时也使用了非常多的xcode插件,尽管官方对于插件制作没有提供不论什么支持,可是载入三方的插件,默认还是被同意的.第三方的插件,须要存放在 ~/Library/Application Su ...
- Flash制作和软件使用
Flash制作和软件使用 2014-11-09 ——君子善假于物也 引子 虽说FLASH在随着HTML5的发展而受阻,尤其移动终端都不再支持它了,但是在一段时间内还是重要的.近期朋友说要结婚,想弄个电 ...
- inception安装步骤---自己整理的安装步骤
inception安装步骤---自己整理的安装步骤2015-09-18 15:51 6185人阅读 评论(1) 收藏 举报 分类: inception相关版权声明:本文为博主原创文章,未经博主允许不得 ...
- mac下执行文件出现Permission Denied的解决
mac 下终端访问文件出现“Permission Denied”解决方案: 一个文件有3种权限,读.写.可执行,你这个文件没有可执行权限,需要加上可执行权限. 1. 终端下先 cd到该文件的目录下 2 ...
- HDU 6166 Senior Pan 二进制分组 + 迪杰斯特拉算法
Senior Pan Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Probl ...
- select version();desc mysql.user;
D:\wamp64\wamp\bin\mysql\mysql5.6.17\bin>mysql -hgoDev -uroot -ppasswordWarning: Using a password ...
- yum 工作原理
MySQL :: A Quick Guide to Using the MySQL Yum Repository https://dev.mysql.com/doc/mysql-yum-repo-qu ...
- 使用MSSQL同步&发布数据库快照遇到错误:对路径“xxxxx”访问被拒绝的解决方法
使用MSSQL同步 数据库同步做后后测试:先在同步那台服务器(服务器A)数据库里修改里面数据库,然后再去被同步那台服务器(服务器B)看下数据有没被同步过去 发布数据库快照遇到错误:对路径“xxxxx” ...
- MQ发送的消息都到了死信队列中了
MQ在发送消息的时候,设置的过期时间太短.(昨天项目上线遇到了,开发中也遇到一次.)谨记!!!
- imagemap的推荐使用方法,前端自适应image maps库
1.map在浏览器的兼容性相对来说是比较好的,这是我在项目中的一个处理方法 推荐到下面网站去画map http://imagemap-generator.dariodomi.de/ 2.画完去gith ...