自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

杂草的专栏

为自己不懂的或者是以解决的问题一个家

  • 博客(2)
  • 资源 (2)
  • 收藏
  • 关注

原创 扩展方法,对象初始化器,集合初始化器的运用

C#3.0 的新特性包括(linq,Lambda表达式,自动属性,推断类型,匿名类,扩展方法,对象初始化器,集合初始化器)今天要用的是扩展方法,对象初始化器,集合初始化器的操作 1:可嵌套的对象初始化的器如图: 2:集合初始化器:   3:扩展方法的使用:请注意1.在一个静态类中定义需要的扩展方法2如果上面定义的扩展方法位于不同的命名空间,使用时记住用

2013-05-15 16:14:22 538

原创 .net/加密与减密

using System.Security.Cryptography;//引人的命名空间///     /// 加密    ///    public class DES    {        ///         /// 创建key        ///         ///         public string CreadKey() {

2013-05-09 19:37:32 464

事件委托加linq的操作

//委托的定义 public delegate string wings(string input); /// <summary> /// 委托方法二匿名 /// </summary> class Program { static void Main(string[] args) { //匿名方法方式 wings w = delegate(string str) { return str.ToUpper(); }; string name = "my name is fly and I like eat apples"; //用数组分开 string[] delete = name.Split(' '); foreach (var item in delete) { //此时的 w 实际上就是匿名 方法 Console.WriteLine(w(item)); } Console.WriteLine("***************************"); //直接打印字符串w 实际上就是 匿名 方法 Console.WriteLine(w(name)); Console.Read(); } }

2013-05-14

wpf的Excel分类导出数据(Aspose)

对学习wpf的朋友们有一定的帮助 /// <summary> /// 工参表分割类, 按区域进行对数据行进行分割 /// </summary> public class AreaSplit { public event EventHandler<StringEventArgs> Opening; public event EventHandler<StringEventArgs> ErrorHappened; public event EventHandler<Int32EventArgs> BeginSplit; public event EventHandler<Int32EventArgs> Splitting; public event EventHandler<StringEventArgs> Saving; public event EventHandler<StringEventArgs> Splitted; private List<string> m_ColNames; /// <summary> /// 执行工参表分割 /// </summary> /// <param name="sourceFile">原始工参文件</param> /// <param name="outPath">分割后输出所在总目录</param> public void StartSplit(string sourceFile, string outPath) { try { Dictionary<string, DataTable> dict = this.SplitToDictionary(sourceFile); if (dict == null) return; this.SaveToExcels(outPath, dict); } catch (Exception ex) { if (ErrorHappened != null) ErrorHappened(this, new StringEventArgs(ex.Message)); } } /// <summary> /// 将工参文件分割为Dictionary<string, DataTable> /// </summary> private Dictionary<string, DataTable> SplitToDictionary(string sourceFile) { if (!File.Exists(sourceFile)) { if (ErrorHappened != null) ErrorHappened(this, new StringEventArgs("指定路径的文件不存在")); return null; } if (this.Opening != null) this.Opening(this, new StringEventArgs("正在读取原始工参表 ...")); Workbook wb = new Workbook(sourceFile); if (wb.Worksheets.Count == 0) { if (ErrorHappened != null) ErrorHappened(this, new StringEventArgs("缺少有效的工作表")); return null; } Worksheet ws = wb.Worksheets[0]; string areaKey = "区域"; int areaPos = -1; // 获取区域所在列号 this.m_ColNames = new List<string>(); int rowCount = ws.Cells.MaxDataRow + 1; int colCount = ws.Cells.MaxDataColumn + 1; for (int i = 0; i < colCount; i++) { string str = ws.Cells[0, i].StringValue; if (str == null) continue; if (str.Equals(areaKey)) { areaPos = i; } this.m_ColNames.Add(str); } if (areaPos == -1) { if (ErrorHappened != null) ErrorHappened(this, new StringEventArgs("找不到正确的区域列")); return null; } if (BeginSplit != null) BeginSplit(this, new Int32EventArgs(rowCount)); Dictionary<string, DataTable> dict = new Dictionary<string, DataTable>(); for (int i = 1; i < rowCount; i++) { string area = ws.Cells[i, areaPos].StringValue; if (string.IsNullOrEmpty(area)) area = "未知区域"; if (!dict.ContainsKey(area)) { DataTable dt = this.GetTable(colCount); dict.Add(area, dt); } DataRow row = dict[area].NewRow(); for (int j = 0; j < colCount; j++) { row[j] = ws.Cells[i, j].StringValue; } dict[area].Rows.Add(row); if (Splitting != null) Splitting(this, new Int32EventArgs(i)); } return dict; } /// <summary> /// 将分割后的数据,按区域分别保存为Excel文档 /// </summary> /// <param name="outPath"></param> /// <param name="dict"></param> private void SaveToExcels(string outPath, Dictionary<string, DataTable> dict) { foreach (string key in dict.Keys) { if (Saving != null) this.Saving(this, new StringEventArgs("正在保存 " + key + "工参表")); DataTable dt = dict[key]; if (outPath.Equals("")) outPath = AppDomain.CurrentDomain.BaseDirectory + "分割后工参"; string dir = outPath + "\\" + key; if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); string fn = dir + "\\" + key + "_" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx"; if (File.Exists(fn)) File.Delete(fn); Workbook wb = new Workbook(); wb.Worksheets.Clear(); Worksheet ws = wb.Worksheets.Add(key + "工参表"); for (int i=0; i<this.m_ColNames.Count; i++) { ws.Cells[0, i].PutValue(this.m_ColNames[i]); ws.Cells.Columns[i].Width += 2; } int rowCount = dt.Rows.Count; int colCount = dt.Columns.Count; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < colCount; j++) ws.Cells[i+1, j].PutValue(dt.Rows[i][j].ToString()); } wb.Save(fn, SaveFormat.Xlsx); } if (Splitted != null) Splitted(this, new StringEventArgs("工参表分割结束")); } private DataTable GetTable(int colCount) { DataTable dt = new DataTable(); for (int i = 0; i < colCount; i++) { DataColumn col = new DataColumn(); col.DataType = typeof(string); dt.Columns.Add(col); } return dt; }

2013-05-06

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除