当前位置: 首页 > news >正文

东莞建站公司运转全网天下有 名学做吃的网站有哪些

东莞建站公司运转全网天下有 名,学做吃的网站有哪些,东莞建设银行,百度怎么投广告Npoi 简介1.整个Excel表格叫做工作表#xff1a;WorkBook(工作薄)#xff0c;包含的叫页(工作表)#xff1a;Sheet#xff1b;行#xff1a;Row#xff1b;单元格Cell。4.忘了告诉大家npoi是做什么的了#xff0c;npoi 能够读写几乎所有的Office 97-2003文件格式#x…Npoi 简介1.整个Excel表格叫做工作表WorkBook(工作薄)包含的叫页(工作表)Sheet行Row单元格Cell。4.忘了告诉大家npoi是做什么的了npoi 能够读写几乎所有的Office 97-2003文件格式至少能够支持Word, PowerPoint, Excel, Visio的格式。使用Npoi创建一个简单的xls文件//创建xls文件private void button1_Click(object sender, EventArgs e){//创建工作薄HSSFWorkbook wk new HSSFWorkbook();//创建一个名称为mySheet的表ISheet tb wk.CreateSheet(mySheet);//创建一行此行为第二行IRow row tb.CreateRow(1);for (int i 0; i 20; i){ICell cell row.CreateCell(i); //在第二行中创建单元格cell.SetCellValue(i);//循环往第二行的单元格中添加数据}using (FileStream fs File.OpenWrite(c:/myxls.xls)) //打开一个xls文件如果没有则自行创建如果存在myxls.xls文件则在创建是不要打开该文件{wk.Write(fs); //向打开的这个xls文件中写入mySheet表并保存。MessageBox.Show(提示创建成功);}}使用Npoi读取一个简单的xls文件//读取xls文件private void button2_Click(object sender, EventArgs e){ StringBuilder sbr new StringBuilder();using (FileStream fs File.OpenRead(c:/myxls.xls)) //打开myxls.xls文件{HSSFWorkbook wk new HSSFWorkbook(fs); //把xls文件中的数据写入wk中for (int i 0; i wk.NumberOfSheets; i) //NumberOfSheets是myxls.xls中总共的表数{ISheet sheet wk.GetSheetAt(i); //读取当前表数据for (int j 0; j sheet.LastRowNum; j) //LastRowNum 是当前表的总行数{IRow row sheet.GetRow(j); //读取当前行数据if (row ! null){sbr.Append(-------------------------------------\r\n); //读取行与行之间的提示界限for (int k 0; k row.LastCellNum; k) //LastCellNum 是当前行的总列数{ICell cell row.GetCell(k); //当前表格if (cell ! null){sbr.Append(cell.ToString()); //获取表格中的数据并转换为字符串类型}}}}}}sbr.ToString();using (StreamWriter wr new StreamWriter(new FileStream(c:/myText.txt, FileMode.Append))) //把读取xls文件的数据写入myText.txt文件中{wr.Write(sbr.ToString());wr.Flush();}}使用Npoi创建一个常用的xls文件//创建一个常用的xls文件private void button3_Click(object sender, EventArgs e){IWorkbook wb new HSSFWorkbook();//创建表ISheet sh wb.CreateSheet(zhiyuan);//设置单元的宽度sh.SetColumnWidth(0, 15 * 256);sh.SetColumnWidth(1, 35 * 256);sh.SetColumnWidth(2, 15 * 256);sh.SetColumnWidth(3, 10 * 256);int i 0;#region 练习合并单元格sh.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 3));//CellRangeAddress()该方法的参数次序是开始行号结束行号开始列号结束列号。IRow row0 sh.CreateRow(0);row0.Height 20 * 20;ICell icell1top0 row0.CreateCell(0);icell1top0.CellStyle Getcellstyle(wb, stylexls.头);icell1top0.SetCellValue(标题合并单元);#endregioni;#region 设置表头IRow row1 sh.CreateRow(1);row1.Height 20 * 20;ICell icell1top row1.CreateCell(0);icell1top.CellStyle Getcellstyle(wb, stylexls.头);icell1top.SetCellValue(网站名);ICell icell2top row1.CreateCell(1);icell2top.CellStyle Getcellstyle(wb, stylexls.头);icell2top.SetCellValue(网址);ICell icell3top row1.CreateCell(2);icell3top.CellStyle Getcellstyle(wb, stylexls.头);icell3top.SetCellValue(百度快照);ICell icell4top row1.CreateCell(3);icell4top.CellStyle Getcellstyle(wb, stylexls.头);icell4top.SetCellValue(百度收录);#endregionusing(FileStream stmFile.OpenWrite(c:/myMergeCell.xls)){wb.Write(stm);MessageBox.Show(提示创建成功);}}#region 定义单元格常用到样式的枚举public enum stylexls{头,url,时间,数字,钱,百分比,中文大写,科学计数法,默认}#endregion#region 定义单元格常用到样式static ICellStyle Getcellstyle(IWorkbook wb, stylexls str){ICellStyle cellStyle wb.CreateCellStyle();//定义几种字体//也可以一种字体写一些公共属性然后在下面需要时加特殊的IFont font12 wb.CreateFont();font12.FontHeightInPoints 10;font12.FontName 微软雅黑;IFont font wb.CreateFont();font.FontName 微软雅黑;//font.Underline 1;下划线IFont fontcolorblue wb.CreateFont();fontcolorblue.Color HSSFColor.OLIVE_GREEN.BLUE.index;fontcolorblue.IsItalic true;//下划线fontcolorblue.FontName 微软雅黑;//边框cellStyle.BorderBottom NPOI.SS.UserModel.BorderStyle.DOTTED;cellStyle.BorderLeft NPOI.SS.UserModel.BorderStyle.HAIR;cellStyle.BorderRight NPOI.SS.UserModel.BorderStyle.HAIR;cellStyle.BorderTop NPOI.SS.UserModel.BorderStyle.DOTTED;//边框颜色cellStyle.BottomBorderColor HSSFColor.OLIVE_GREEN.BLUE.index;cellStyle.TopBorderColor HSSFColor.OLIVE_GREEN.BLUE.index;//背景图形我没有用到过。感觉很丑//cellStyle.FillBackgroundColor HSSFColor.OLIVE_GREEN.BLUE.index;//cellStyle.FillForegroundColor HSSFColor.OLIVE_GREEN.BLUE.index;cellStyle.FillForegroundColor HSSFColor.WHITE.index;// cellStyle.FillPattern FillPatternType.NO_FILL;cellStyle.FillBackgroundColor HSSFColor.BLUE.index;//水平对齐cellStyle.Alignment NPOI.SS.UserModel.HorizontalAlignment.LEFT;//垂直对齐cellStyle.VerticalAlignment VerticalAlignment.CENTER;//自动换行cellStyle.WrapText true;//缩进;当设置为1时前面留的空白太大了。希旺官网改进。或者是我设置的不对cellStyle.Indention 0;//上面基本都是设共公的设置//下面列出了常用的字段类型switch (str){case stylexls.头:// cellStyle.FillPattern FillPatternType.LEAST_DOTS;cellStyle.SetFont(font12);break;case stylexls.时间:IDataFormat datastyle wb.CreateDataFormat();cellStyle.DataFormat datastyle.GetFormat(yyyy/mm/dd);cellStyle.SetFont(font);break;case stylexls.数字:cellStyle.DataFormat HSSFDataFormat.GetBuiltinFormat(0.00);cellStyle.SetFont(font);break;case stylexls.钱:IDataFormat format wb.CreateDataFormat();cellStyle.DataFormat format.GetFormat(#,##0);cellStyle.SetFont(font);break;case stylexls.url:fontcolorblue.Underline 1;cellStyle.SetFont(fontcolorblue);break;case stylexls.百分比:cellStyle.DataFormat HSSFDataFormat.GetBuiltinFormat(0.00%);cellStyle.SetFont(font);break;case stylexls.中文大写:IDataFormat format1 wb.CreateDataFormat();cellStyle.DataFormat format1.GetFormat([DbNum2][$-804]0);cellStyle.SetFont(font);break;case stylexls.科学计数法:cellStyle.DataFormat HSSFDataFormat.GetBuiltinFormat(0.00E00);cellStyle.SetFont(font);break;case stylexls.默认:cellStyle.SetFont(font);break;}return cellStyle;}#endregion提示1.以上使用npoi版本为1.2.5版本版本目前属于最高版本跟以前版本的使用是有些差别的。2.使用以上代码需要添加两个npoi的dll。Ionic.Zip.dllNPOI.dll错误提示The supplied data appears to be in the Office 2007 XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)错误原因HSSFWorkbook:是操作Excel2003以前(包括2003)的版本扩展名是.xlsXSSFWorkbook:是操作Excel2007的版本扩展名是.xlsx解决方案(引用npoi2.0)ISheet sheet;FileStream fs null;try{fs new FileStream(txtPath.Text, FileMode.Open, FileAccess.Read);HSSFWorkbook wk new HSSFWorkbook(fs);sheet wk.GetSheet(sheetName);}catch{fs new FileStream(txtPath.Text, FileMode.Open, FileAccess.Read);XSSFWorkbook wk new XSSFWorkbook(fs);sheet wk.GetSheet(sheetName);}finally{fs.Close();fs.Dispose();}if (sheet.LastRowNum 1){MessageBox.Show(表内容不能为空);return;}for (int j 1; j sheet.LastRowNum; j)
http://www.zqtcl.cn/news/471470/

相关文章:

  • 商务网站建设哪家好绍兴网站建设做网站
  • 网站域名管理东莞网页设计和网页制作
  • 网站建设与制作报价网站app制作
  • 下载可以做动漫的我的世界视频网站长沙网站seo技巧
  • 汕头网站制作推荐制作影视视频的软件
  • 定制程序网站宁波英文网站建设
  • 安康公司做网站网页设计怎么设计
  • 小型企业网站系统南京seo外包平台
  • 曲靖网站制作邢台网站制作那家便宜
  • wordpress中portfolio重庆网站seo按天计费
  • 做淘客网站需要多大的空间工程公司名称大全简单大气
  • 康县建设局网站网站做优化
  • 笔记网站开发代码下载了wordpress后
  • 北京招聘高级网站开发工程师域名最新通知
  • 企业如何实现高端网站建设西安百度推广开户
  • 广西城乡住房建设厅网站首页本地 安装 WordPress主题
  • 网站开发 技术方案设计一个软件需要多少钱
  • 网站如何做死链接提交建设银行网站官网网址
  • 网站难做吗承德平台
  • 手机备案网站营销网络建设怎么写
  • 建个网站要花多少钱WordPress密码重设怎么改
  • 招商网站建设免费网站改版 升级的目的
  • 安徽圣力建设集团网站如何自己开发微信小程序
  • 学院网站板块盘多多搜索引擎入口
  • 网站seo内部优化wordpress建站网站报错
  • 网站建设科技国外网站入口
  • 怎样用网站做淘宝推广免费的项目管理软件
  • 共青城网站建设微网站开发报价
  • 网站建设选超速云建站网站建设公司比较
  • 芜湖网络科技有限公司沈阳网站推广优化公司哪家好