1、引用NPOI;

using NPOI.HSSF.UserModel;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;

2、导出excel

  1. 1 private void btnadd_MouseUp(object sender, MouseButtonEventArgs e)
  2. 2 {
  3. 3 try
  4. 4 {
  5. 5 #region 打印导出无统计数据
  6. 6 if (dt != null && dt.Rows.Count > 0)
  7. 7 {
  8. 8 //创建工作薄
  9. 9 HSSFWorkbook wb = new HSSFWorkbook();
  10. 10 //创建一个名称为mySheet的表
  11. 11 ISheet sh = wb.CreateSheet("mySheet");
  12. 12 #region 设置表格内容
  13. 13 for (int i = 0; i < dt.Rows.Count; i++)
  14. 14 {
  15. 15 SetRow(wb, sh, i * 2);//设置表头
  16. 16 IRow row = sh.CreateRow(i * 2 + 1);
  17. 17 for (int j = 2; j < dt.Columns.Count - 7; j++)
  18. 18 {
  19. 19 if (j < 4)
  20. 20 {
  21. 21 string content = dt.Rows[i][j].ToString();
  22. 22 ICell cell = row.CreateCell(j - 2);
  23. 23 cell.SetCellValue(content);
  24. 24 }
  25. 25 else if (j > 4)
  26. 26 {
  27. 27 string content = dt.Rows[i][j].ToString();
  28. 28 ICell cell = row.CreateCell(j - 3);
  29. 29 cell.SetCellValue(content);
  30. 30 }
  31. 31 }
  32. 32 }
  33. 33 string saveFileName = "人员工资表.xls";
  34. 34 //FileStream fs=new FileStream();
  35. 35 SaveFileDialog saveDialog = new SaveFileDialog();
  36. 36 saveDialog.DefaultExt = "xls";
  37. 37 saveDialog.Filter = "Excel文件|*.xls";
  38. 38 saveDialog.FileName = saveFileName;
  39. 39 saveDialog.ShowDialog();
  40. 40 saveFileName = saveDialog.FileName;
  41. 41 if (saveFileName.IndexOf(":") < 0) return; //被点了取消
  42. 42 if (saveFileName != "")
  43. 43 {
  44. 44 using (FileStream fs = File.OpenWrite(saveDialog.FileName))//打开一个xls文件,如果没有则自行创建,如果存在myxls.xls文件则在创建是不要打开该文件
  45. 45 {
  46. 46 try
  47. 47 {
  48. 48 wb.Write(fs);
  49. 49 MessageBox.Show("导出成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  50. 50 }
  51. 51 catch (Exception ex)
  52. 52 {
  53. 53 MessageBox.Show("导出文件时出错,文件可能正被打开!\n" + ex.Message, "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  54. 54 }
  55. 55 fs.Flush();
  56. 56 fs.Dispose();
  57. 57 fs.Close();
  58. 58 }
  59. 59 }
  60. 60 else
  61. 61 {
  62. 62 MessageBox.Show("请选择数据源!");
  63. 63 }
  64. 64 #endregion
  65. 65 }
  66. 66 else
  67. 67 {
  68. 68 MessageBox.Show("请选择数据源!");
  69. 69 }
  70. 70 #endregion
  71. 71 }
  72. 72 catch (Exception ex)
  73. 73 {
  74. 74 MessageBox.Show(ex.Message, "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  75. 75 }
  76. 76 }

3、导入excel

  1. 1 private void btnexport_MouseUp(object sender, MouseButtonEventArgs e)
  2. 2 {
  3. 3 try
  4. 4 {
  5. 5 string str = "";
  6. 6 string Error = "";
  7. 7 OpenFileDialog of = new OpenFileDialog();
  8. 8 of.DefaultExt = "xls";
  9. 9 of.Filter = "Excel文件|*.xls";
  10. 10 of.ShowDialog();
  11. 11 if (string.IsNullOrEmpty(of.FileName))
  12. 12 {
  13. 13 return;
  14. 14 }
  15. 15 if (of.CheckFileExists == true) //路径存在
  16. 16 {
  17. 17 string path = of.FileName;
  18. 18 using (FileStream fs = File.OpenRead(path)) //打开myxls.xls文件
  19. 19 {
  20. 20 HSSFWorkbook wk = new HSSFWorkbook(fs); //把xls文件中的数据写入wk中
  21. 21 #region 验证
  22. 22 for (int i = 0; i < wk.NumberOfSheets; i++) //NumberOfSheets是myxls.xls中总共的表数
  23. 23 {
  24. 24 ISheet sheet = wk.GetSheetAt(i); //读取当前表数据
  25. 25 for (int j = 1; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数
  26. 26 {
  27. 27 IRow row = sheet.GetRow(j); //读取当前行数据
  28. 28 if (row != null)
  29. 29 {
  30. 30 for (int k = 0; k <= row.LastCellNum; k++) //LastCellNum 是当前行的总列数
  31. 31 {
  32. 32 if (k > 29)
  33. 33 {
  34. 34 break;
  35. 35 }
  36. 36 ICell cell = row.GetCell(k); //当前表格
  37. 37 if (cell != null)
  38. 38 {
  39. 39 string content = cell.ToString();
  40. 40 #region 验证
  41. 41
  42. 42 if (k > 3 && k < 30)
  43. 43 {
  44. 44 if (!new System.Text.RegularExpressions.Regex(@"^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$").IsMatch(content.Trim()))
  45. 45 {
  46. 46 Error += "表" + (i + 1) + "行" + (j + 1) + "列" + (k + 1) + "中有非法字符;\r\n";
  47. 47 }
  48. 48 }
  49. 49 else if (k == 1)
  50. 50 {
  51. 51 if (!new System.Text.RegularExpressions.Regex(@"^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$").IsMatch(content.Trim()))
  52. 52 {
  53. 53 Error += "表" + (i + 1) + "行" + (j + 1) + "列" + (k + 1) + "中有非法字符;\r\n";
  54. 54 }
  55. 55 }
  56. 56 #endregion
  57. 57 }
  58. 58 }
  59. 59 }
  60. 60 }
  61. 61 }
  62. 62 if (Error.Length > 0)
  63. 63 {
  64. 64 MessageBox.Show(Error + "请验证!", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  65. 65 return;
  66. 66 }
  67. 67
  68. 68 #endregion
  69. 69
  70. 70 for (int i = 0; i < wk.NumberOfSheets; i++) //NumberOfSheets是myxls.xls中总共的表数
  71. 71 {
  72. 72 ISheet sheet = wk.GetSheetAt(i); //读取当前表数据
  73. 73 string depid = "";
  74. 74 string userid = "";
  75. 75 string deptname = "";
  76. 76 for (int j = 1; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数
  77. 77 {
  78. 78 IRow row = sheet.GetRow(j); //读取当前行数据
  79. 79 if (row != null)
  80. 80 {
  81. 81 str = str + "insert into wage(depid,depname,mon,userid,username,code,gwgz,xl,jishu,zili,jbgz,gl,weisheng,menzhen,tizu,zjjt,jiaotong,zinv,zbbt,jixiao,bufa,ycxj,yjlgz,yfhj,jfz,baoyang,yibao,shiye,fangjin,nianjin,nashui,sfgz,createdate) values(";
  82. 82 for (int k = 0; k <= row.LastCellNum; k++) //LastCellNum 是当前行的总列数
  83. 83 {
  84. 84 if (k > 29)
  85. 85 {
  86. 86 break;
  87. 87 }
  88. 88 ICell cell = row.GetCell(k); //当前表格
  89. 89 if (cell != null)
  90. 90 {
  91. 91 string content = cell.ToString();
  92. 92
  93. 93 #region 验证
  94. 94 if (!string.IsNullOrEmpty(content))
  95. 95 {
  96. 96 if (k == 0)
  97. 97 {
  98. 98 string sql = @"select depid,userid from wage where depname='" + content + "'";
  99. 99 DataSet ds = new DataBase().GetDataSet(sql);
  100. 100 DataTable newDT = ds.Tables[0];
  101. 101 depid = newDT.Rows[0][0].ToString();
  102. 102 userid = newDT.Rows[0][1].ToString();
  103. 103 if (string.IsNullOrEmpty(depid))
  104. 104 {
  105. 105 depid = "99999";
  106. 106 }
  107. 107 if (string.IsNullOrEmpty(userid))
  108. 108 {
  109. 109 userid = "1122222";
  110. 110 }
  111. 111 deptname = content;
  112. 112 str = str + "" + depid + ",'" + deptname + "',";
  113. 113 }
  114. 114 else
  115. 115 {
  116. 116 if (k == 1)
  117. 117 { str = str + content + ","; }
  118. 118 else if (k == 2)
  119. 119 {
  120. 120 str = str + "" + userid + ",'" + content + "',";
  121. 121 }
  122. 122 else
  123. 123 {
  124. 124 if (k > 3)
  125. 125 {
  126. 126 if (!new System.Text.RegularExpressions.Regex(@"^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$").IsMatch(content.Trim()))
  127. 127 {
  128. 128 MessageBox.Show("文件数据内有非数字,请修改!");
  129. 129 }
  130. 130 else
  131. 131 {
  132. 132 str = str + "'" + content + "',";
  133. 133 }
  134. 134 }
  135. 135 else
  136. 136 {
  137. 137 str = str + "'" + content + "',";
  138. 138 }
  139. 139 }
  140. 140 }
  141. 141 }
  142. 142 else
  143. 143 {
  144. 144 MessageBox.Show("文件内有空数据,请重新导入!");
  145. 145 }
  146. 146 #endregion
  147. 147 if (i == sheet.LastRowNum - 2)
  148. 148 {
  149. 149 break;
  150. 150 }
  151. 151 }
  152. 152 else
  153. 153 {
  154. 154 MessageBox.Show("文件为空,请重新导入!");
  155. 155 }
  156. 156 }
  157. 157 //str = str.ToString().Substring(0, str.Length - 1);
  158. 158 str = str + "'" + DateTime.Now + "'";
  159. 159 str = str + ");";
  160. 160 }
  161. 161 int result = new DataBase().ExecuteSQL(str);
  162. 162 str = "";
  163. 163 }
  164. 164 }
  165. 165 MessageBox.Show("导入成功", "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk);
  166. 166 //重新绑定
  167. 167 BindData(int.Parse(common.SelectedValue.ToString()));
  168. 168 }
  169. 169 }
  170. 170 else
  171. 171 {
  172. 172 MessageBox.Show("文件不存在", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  173. 173 }
  174. 174 }
  175. 175 catch (Exception ex)
  176. 176 {
  177. 177 MessageBox.Show(ex.Message, "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  178. 178 }
  179. 179
  180. 180 }

4、公共方法

  1. 1 /// <summary>
  2. 2 /// 打印导出表头
  3. 3 /// </summary>
  4. 4 /// <param name="wb"></param>
  5. 5 /// <param name="sh"></param>
  6. 6 /// <param name="num"></param>
  7. 7 /// <returns></returns>
  8. 8 public IRow SetRow(HSSFWorkbook wb, ISheet sh, int num)
  9. 9 {
  10. 10 #region 设置表头
  11. 11 IRow row1 = sh.CreateRow(num);
  12. 12 row1.Height = 22 * 22;
  13. 13 ICell icell1top = row1.CreateCell(0);
  14. 14 icell1top.CellStyle = Getcellstyle(wb, stylexls.头);
  15. 15 icell1top.SetCellValue("部门");
  16. 16 ICell icell2top = row1.CreateCell(1);
  17. 17 icell2top.CellStyle = Getcellstyle(wb, stylexls.头);
  18. 18 icell2top.SetCellValue("月份");
  19. 19 ICell icell3top = row1.CreateCell(2);
  20. 20 icell3top.CellStyle = Getcellstyle(wb, stylexls.头);
  21. 21 icell3top.SetCellValue("职员");
  22. 22 ICell icell4top = row1.CreateCell(3);
  23. 23 icell4top.CellStyle = Getcellstyle(wb, stylexls.头);
  24. 24 icell4top.SetCellValue("人员编码");
  25. 25 ICell icell5top = row1.CreateCell(4);
  26. 26 icell5top.CellStyle = Getcellstyle(wb, stylexls.头);
  27. 27 icell5top.SetCellValue("岗位工资");
  28. 28 ICell icell6top = row1.CreateCell(5);
  29. 29 icell6top.CellStyle = Getcellstyle(wb, stylexls.头);
  30. 30 icell6top.SetCellValue("学历");
  31. 31 ICell icell7top = row1.CreateCell(6);
  32. 32 icell7top.CellStyle = Getcellstyle(wb, stylexls.头);
  33. 33 icell7top.SetCellValue("技术");
  34. 34 ICell icell8top = row1.CreateCell(7);
  35. 35 icell8top.CellStyle = Getcellstyle(wb, stylexls.头);
  36. 36 icell8top.SetCellValue("资历");
  37. 37 ICell icell9top = row1.CreateCell(8);
  38. 38 icell9top.CellStyle = Getcellstyle(wb, stylexls.头);
  39. 39 icell9top.SetCellValue("基本工资");
  40. 40 ICell icell10top = row1.CreateCell(9);
  41. 41 icell10top.CellStyle = Getcellstyle(wb, stylexls.头);
  42. 42 icell10top.SetCellValue("工龄");
  43. 43 ICell icell11top = row1.CreateCell(10);
  44. 44 icell11top.CellStyle = Getcellstyle(wb, stylexls.头);
  45. 45 icell11top.SetCellValue("卫生");
  46. 46 ICell icell12top = row1.CreateCell(11);
  47. 47 icell12top.CellStyle = Getcellstyle(wb, stylexls.头);
  48. 48 icell12top.SetCellValue("门诊");
  49. 49 ICell icell13top = row1.CreateCell(12);
  50. 50 icell13top.CellStyle = Getcellstyle(wb, stylexls.头);
  51. 51 icell13top.SetCellValue("提租");
  52. 52 ICell icell14top = row1.CreateCell(13);
  53. 53 icell14top.CellStyle = Getcellstyle(wb, stylexls.头);
  54. 54 icell14top.SetCellValue("专家津贴");
  55. 55 ICell icell15top = row1.CreateCell(14);
  56. 56 icell15top.CellStyle = Getcellstyle(wb, stylexls.头);
  57. 57 icell15top.SetCellValue("专家交通");
  58. 58 ICell icell16top = row1.CreateCell(15);
  59. 59 icell16top.CellStyle = Getcellstyle(wb, stylexls.头);
  60. 60 icell16top.SetCellValue("子女");
  61. 61 ICell icell17top = row1.CreateCell(16);
  62. 62 icell17top.CellStyle = Getcellstyle(wb, stylexls.头);
  63. 63 icell17top.SetCellValue("值班补贴");
  64. 64 ICell icell18top = row1.CreateCell(17);
  65. 65 icell18top.CellStyle = Getcellstyle(wb, stylexls.头);
  66. 66 icell18top.SetCellValue("绩效");
  67. 67 ICell icell19top = row1.CreateCell(18);
  68. 68 icell19top.CellStyle = Getcellstyle(wb, stylexls.头);
  69. 69 icell19top.SetCellValue("补发");
  70. 70 ICell icell20top = row1.CreateCell(19);
  71. 71 icell20top.CellStyle = Getcellstyle(wb, stylexls.头);
  72. 72 icell20top.SetCellValue("一次性奖");
  73. 73 ICell icell21top = row1.CreateCell(20);
  74. 74 icell21top.CellStyle = Getcellstyle(wb, stylexls.头);
  75. 75 icell21top.SetCellValue("月奖励工资");
  76. 76 ICell icell22top = row1.CreateCell(21);
  77. 77 icell22top.CellStyle = Getcellstyle(wb, stylexls.头);
  78. 78 icell22top.SetCellValue("应发合计");
  79. 79 ICell icell23top = row1.CreateCell(22);
  80. 80 icell23top.CellStyle = Getcellstyle(wb, stylexls.头);
  81. 81 icell23top.SetCellValue("局租房");
  82. 82 ICell icell24top = row1.CreateCell(23);
  83. 83 icell24top.CellStyle = Getcellstyle(wb, stylexls.头);
  84. 84 icell24top.SetCellValue("保养");
  85. 85 ICell icell25top = row1.CreateCell(24);
  86. 86 icell25top.CellStyle = Getcellstyle(wb, stylexls.头);
  87. 87 icell25top.SetCellValue("医保");
  88. 88 ICell icell26top = row1.CreateCell(25);
  89. 89 icell26top.CellStyle = Getcellstyle(wb, stylexls.头);
  90. 90 icell26top.SetCellValue("失业");
  91. 91 ICell icell27top = row1.CreateCell(26);
  92. 92 icell27top.CellStyle = Getcellstyle(wb, stylexls.头);
  93. 93 icell27top.SetCellValue("房金");
  94. 94 ICell icell28top = row1.CreateCell(27);
  95. 95 icell28top.CellStyle = Getcellstyle(wb, stylexls.头);
  96. 96 icell28top.SetCellValue("年金");
  97. 97 ICell icell29top = row1.CreateCell(28);
  98. 98 icell29top.CellStyle = Getcellstyle(wb, stylexls.头);
  99. 99 icell29top.SetCellValue("纳税");
  100. 100 ICell icell30top = row1.CreateCell(29);
  101. 101 icell30top.CellStyle = Getcellstyle(wb, stylexls.头);
  102. 102 icell30top.SetCellValue("实发工资");
  103. 103 #endregion
  104. 104 return row1;
  105. 105 }
  1. 1 #region 定义单元格常用到样式的枚举
  2. 2 public enum stylexls
  3. 3 {
  4. 4 头,
  5. 5 url,
  6. 6 时间,
  7. 7 数字,
  8. 8 钱,
  9. 9 百分比,
  10. 10 中文大写,
  11. 11 科学计数法,
  12. 12 默认
  13. 13 }
  14. 14 #endregion
  15. 15 #region 定义单元格常用到的样式
  16. 16 static ICellStyle Getcellstyle(IWorkbook wb, stylexls str)
  17. 17 {
  18. 18 ICellStyle cellStyle = wb.CreateCellStyle();
  19. 19
  20. 20 //定义几种字体
  21. 21 //也可以一种字体,写一些公共属性,然后在下面需要时加特殊的
  22. 22 IFont font12 = wb.CreateFont();
  23. 23 font12.FontHeightInPoints = 10;
  24. 24 font12.FontName = "微软雅黑";
  25. 25
  26. 26
  27. 27 IFont font = wb.CreateFont();
  28. 28 font.FontName = "微软雅黑";
  29. 29 //font.Underline = 1;下划线
  30. 30
  31. 31
  32. 32 IFont fontcolorblue = wb.CreateFont();
  33. 33 fontcolorblue.Color = HSSFColor.OliveGreen.Blue.Index;
  34. 34 fontcolorblue.IsItalic = true;//下划线
  35. 35 fontcolorblue.FontName = "微软雅黑";
  36. 36
  37. 37
  38. 38 //边框
  39. 39 cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  40. 40 cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  41. 41 cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  42. 42 cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  43. 43 //水平对齐
  44. 44 cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  45. 45
  46. 46 //垂直对齐
  47. 47 cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
  48. 48
  49. 49 //自动换行
  50. 50 cellStyle.WrapText = true;
  51. 51
  52. 52 //缩进;当设置为1时,前面留的空白太大了。希旺官网改进。或者是我设置的不对
  53. 53 cellStyle.Indention = 0;
  54. 54
  55. 55 //上面基本都是设共公的设置
  56. 56 //下面列出了常用的字段类型
  57. 57 switch (str)
  58. 58 {
  59. 59 case stylexls.头:
  60. 60 // cellStyle.FillPattern = FillPatternType.LEAST_DOTS;
  61. 61 cellStyle.SetFont(font12);
  62. 62 break;
  63. 63 case stylexls.时间:
  64. 64 IDataFormat datastyle = wb.CreateDataFormat();
  65. 65
  66. 66 cellStyle.DataFormat = datastyle.GetFormat("yyyy/mm/dd");
  67. 67 cellStyle.SetFont(font);
  68. 68 break;
  69. 69 case stylexls.数字:
  70. 70 cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00");
  71. 71 cellStyle.SetFont(font);
  72. 72 break;
  73. 73 case stylexls.钱:
  74. 74 IDataFormat format = wb.CreateDataFormat();
  75. 75 cellStyle.DataFormat = format.GetFormat("¥#,##0");
  76. 76 cellStyle.SetFont(font);
  77. 77 break;
  78. 78 case stylexls.百分比:
  79. 79 cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00%");
  80. 80 cellStyle.SetFont(font);
  81. 81 break;
  82. 82 case stylexls.中文大写:
  83. 83 IDataFormat format1 = wb.CreateDataFormat();
  84. 84 cellStyle.DataFormat = format1.GetFormat("[DbNum2][$-804]0");
  85. 85 cellStyle.SetFont(font);
  86. 86 break;
  87. 87 case stylexls.科学计数法:
  88. 88 cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00E+00");
  89. 89 cellStyle.SetFont(font);
  90. 90 break;
  91. 91 case stylexls.默认:
  92. 92 cellStyle.SetFont(font);
  93. 93 break;
  94. 94 }
  95. 95 return cellStyle;
  96. 96
  97. 97
  98. 98 }
  99. 99 #endregion

NPOI导入excel的更多相关文章

  1. ASP.NET MVC NPOI导入Excel DataTable批量导入到数据库

    使用NPOI导入Excel 首先在MVC项目中导入NPOI 查询NPOI安装,排序依据,选择:最高下载量,选择第一个. 在控制器中创建ExcelController 在Index视图中写入代码: @u ...

  2. 使用NPOI导入Excel注意日期格式和数字格式

    //使用NPOI导入Excel public static DataTable importExcelToDataSetUsingNPOI(string FilePath, string fileNa ...

  3. 使用npoi导入Excel - 带合并单元格--附代码

    之前我们在使用npoi导入excel表格的时候,往往会遇见那种带有合并单元格的数据在导入的时候出现合并为空的问题, 也就是只有第一条有数据,其余均为空白.在网上翻了半天也没有找到合适的解决方案,最后还 ...

  4. NPOI 导入Excel和读取Excel

    1.整个Excel表格叫做工作表:WorkBook(工作薄),包含的叫页(工作表):Sheet:行:Row:单元格Cell. 2.NPOI是POI的C#版本,NPOI的行和列的index都是从0开始 ...

  5. NPOI导入excel为datatable (xls xlsx xlsm)

    使用NPOI导入导出Excel(xls/xlsx)数据到DataTable中 http://www.cnblogs.com/songrun/p/3547738.html NPOI 2.0教程 – 自动 ...

  6. .Net Core 使用 NPOI 导入Excel

    由于之前在网上查阅一些资料发现总是不能编译通过,不能正常使用,现把能正常使用的代码贴出: /// <summary> /// Excel导入帮助类 /// </summary> ...

  7. NPOI导入Excel日期格式的处理 - 附类型格式匹配表

    传统操作Excel方法在部署的时候遇到很多问题,如目标主机需要安装Excel.64位电脑不支持.需要安装相关驱动程序等.所以我们一般会使用开源的NPOI来替代传统的Excel操作方法,NPOI的优点是 ...

  8. NPOI导入excel文件为DataTable,使用SqlBulkCopy添加到数据库表

    public DataTable ExcelToDataTable(Stream stream, string fileName) { DataTable data = new DataTable() ...

  9. Winforn中导入Excel并显示然后获取多选框选中的内容

    场景 使用NPOI导入Excel并赋值给DataTable,然后显示在DataGrdView上,并且添加多选框,然后获取选中行的内容. Winform中使用NPOI实现Excel导入并赋值给DataT ...

随机推荐

  1. Linux 学习笔记04丨Linux的用户和用户组管理

    Chapter 3. 用户和用户组管理 由于Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以该账号身份进入系统. 3.0 用户与 ...

  2. ModelViewSet + ModelSerializer

     ModelSerializer (封装好的序列化器,不需要我们写字段) from rest_framework import serializers from .models import * cl ...

  3. 基于FPGA的VGA显示实验设计

    基于FPGA的VGA显示实验设计 成果展示(优酷视频): 视频: 基于FPGA的VGA显示技术(手机控制) http://v.youku.com/v_show/id_XNjk4ODE3ODUy.htm ...

  4. 简单dp水题

    #include <bits/stdc++.h> using namespace std; #define limit (100 + 5)//防止溢出 #define INF 0x3f3f ...

  5. PyQt学习随笔:Model/View开发时在view数据项中设置不同角色数据的方法

    在往Model中通过QStandardItem等类插入数据项时,除了实际插入的存储数据,还可以设置不同角色(请参考<PyQt学习随笔:Model/View中诸如DisplayRole的数据角色及 ...

  6. PyQt(Python+Qt)学习随笔:QAbstractItemView的dragEnabled属性的困惑

    老猿Python博文目录 老猿Python博客地址 dragEnabled属性用于控制视图是否支持拖拽,可以通过dragEnabled().setDragEnabled(bool enable)进行属 ...

  7. 【学习笔记】K-D tree 区域查询时间复杂度简易证明

    查询算法的流程 如果查询与当前结点的区域无交集,直接跳出. 如果查询将当前结点的区域包含,直接跳出并上传答案. 有交集但不包含,继续递归求解. K-D Tree 如何划分区域 可以借助下文图片理解. ...

  8. 转:什么是Shingling算法

    shingling算法用于计算两个文档的相似度,例如,用于网页去重.维基百科对w-shingling的定义如下: In natural language processing a w-shinglin ...

  9. 微信小程序日期转换、比较、加减

    直接上干货: 在utils目录下新建一个dateUtil.js,代码如下:(在需要用的地方引入这个js,调用相关方法传入对应参数就可以使用了) 该工具脚本,实用性很高,通用于各类前端项目,熟悉后亦可以 ...

  10. 女朋友突然问我DNS是个啥....

    女朋友突然问我DNS是个啥.... 今天晚上我正在床上躺着刷手机,然后我女朋友突然说她的电脑坏了.说连着WIFi上不了网,让我给她看一下.(这就是有个程序员男朋友的好处) 然后我拿到电脑看了一下发现访 ...