NPOI. DLL usage. Cell, style, font, color, row height, width. Reading and writing Excel

From , 5 Years ago, written in C#, viewed 145 times.
URL https://pastebin.vip/view/743c41a9
  1. 1.25 NPOI.dll
  2.  
  3. using System;
  4.  
  5.  
  6. using System.Collections.Generic;
  7.  
  8. using System.ComponentModel;
  9.  
  10. using System.Data;
  11.  
  12. using System.Drawing;
  13.  
  14. using System.Linq;
  15.  
  16. using System.Text;
  17.  
  18. using System.Windows.Forms;
  19.  
  20. using System.Data.SqlClient;
  21.  
  22. using NPOI.HSSF.UserModel;
  23.  
  24. using NPOI.HPSF;
  25.  
  26. using NPOI.POIFS.FileSystem;
  27.  
  28. using NPOI.HSSF.Util;
  29.  
  30. using NPOI.SS.UserModel;
  31.  
  32. using System.IO;
  33.  
  34. using SqlHelPerXHC;
  35.  
  36. using NPOI.HSSF.Record.CF;
  37.  
  38. namespace Excl
  39.  
  40. {
  41.  
  42.     public partial class Form1 : Form
  43.  
  44.     {
  45.  
  46.         //http://tonyqus.sinaapp.com/page/4  官网使用说明
  47.  
  48.         public Form1()
  49.  
  50.         {
  51.  
  52.             InitializeComponent();
  53.  
  54.         }
  55.  
  56.         #region 定义单元格常用到样式的枚举
  57.  
  58.         public enum stylexls
  59.  
  60.         {
  61.  
  62.             头,
  63.  
  64.             url,
  65.  
  66.             时间,
  67.  
  68.             数字,
  69.  
  70.             钱,
  71.  
  72.             百分比,
  73.  
  74.             中文大写,
  75.  
  76.             科学计数法,
  77.  
  78.             默认
  79.  
  80.         }
  81.  
  82.         #endregion
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.         #region 定义单元格常用到样式
  91.  
  92.         static ICellStyle Getcellstyle(IWorkbook wb, stylexls str)
  93.  
  94.         {
  95.  
  96.             ICellStyle cellStyle = wb.CreateCellStyle();
  97.  
  98.  
  99.  
  100.  
  101.             //定义几种字体
  102.  
  103.             //也可以一种字体,写一些公共属性,然后在下面需要时加特殊的
  104.  
  105.             IFont font12 = wb.CreateFont();
  106.  
  107.             font12.FontHeightInPoints = 10;
  108.  
  109.             font12.FontName = "微软雅黑";
  110.  
  111.  
  112.  
  113.  
  114.            
  115.  
  116.             IFont font = wb.CreateFont();
  117.  
  118.             font.FontName = "微软雅黑";
  119.  
  120.             //font.Underline = 1;下划线
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.             IFont fontcolorblue = wb.CreateFont();
  129.  
  130.             fontcolorblue.Color = HSSFColor.OLIVE_GREEN.BLUE.index;
  131.  
  132.             fontcolorblue.IsItalic = true;//下划线
  133.  
  134.             fontcolorblue.FontName = "微软雅黑";
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.             //边框
  143.  
  144.             cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.DOTTED;
  145.  
  146.             cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.HAIR;
  147.  
  148.             cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.HAIR;
  149.  
  150.             cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.DOTTED;
  151.  
  152.             //边框颜色
  153.  
  154.             cellStyle.BottomBorderColor = HSSFColor.OLIVE_GREEN.BLUE.index;
  155.  
  156.             cellStyle.TopBorderColor = HSSFColor.OLIVE_GREEN.BLUE.index;
  157.  
  158.  
  159.  
  160.  
  161.             //背景图形,我没有用到过。感觉很丑
  162.  
  163.             //cellStyle.FillBackgroundColor = HSSFColor.OLIVE_GREEN.BLUE.index;
  164.  
  165.             //cellStyle.FillForegroundColor = HSSFColor.OLIVE_GREEN.BLUE.index;
  166.  
  167.             cellStyle.FillForegroundColor = HSSFColor.WHITE.index;
  168.  
  169.             // cellStyle.FillPattern = FillPatternType.NO_FILL;
  170.  
  171.             cellStyle.FillBackgroundColor = HSSFColor.MAROON.index;
  172.  
  173.            
  174.  
  175.             //水平对齐
  176.  
  177.             cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.LEFT;
  178.  
  179.  
  180.  
  181.  
  182.             //垂直对齐
  183.  
  184.             cellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  185.  
  186.  
  187.  
  188.  
  189.             //自动换行
  190.  
  191.             cellStyle.WrapText = true;
  192.  
  193.  
  194.  
  195.  
  196.             //缩进;当设置为1时,前面留的空白太大了。希旺官网改进。或者是我设置的不对
  197.  
  198.             cellStyle.Indention = 0;
  199.  
  200.  
  201.  
  202.  
  203.             //上面基本都是设共公的设置
  204.  
  205.             //下面列出了常用的字段类型
  206.  
  207.             switch (str)
  208.  
  209.             {
  210.  
  211.                 case stylexls.:
  212.  
  213.                     // cellStyle.FillPattern = FillPatternType.LEAST_DOTS;
  214.  
  215.                     cellStyle.SetFont(font12);
  216.  
  217.                     break;
  218.  
  219.                 case stylexls.时间:
  220.  
  221.                     IDataFormat datastyle = wb.CreateDataFormat();
  222.  
  223.  
  224.  
  225.  
  226.                     cellStyle.DataFormat = datastyle.GetFormat("yyyy/mm/dd");
  227.  
  228.                     cellStyle.SetFont(font);
  229.  
  230.                     break;
  231.  
  232.                 case stylexls.数字:
  233.  
  234.                     cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00");
  235.  
  236.                     cellStyle.SetFont(font);
  237.  
  238.                     break;
  239.  
  240.                 case stylexls.:
  241.  
  242.                     IDataFormat format = wb.CreateDataFormat();
  243.  
  244.                     cellStyle.DataFormat = format.GetFormat("¥#,##0");
  245.  
  246.                     cellStyle.SetFont(font);
  247.  
  248.                     break;
  249.  
  250.                 case stylexls.url:
  251.  
  252.                     fontcolorblue.Underline = 1;
  253.  
  254.                     cellStyle.SetFont(fontcolorblue);
  255.  
  256.                     break;
  257.  
  258.                 case stylexls.百分比:
  259.  
  260.                     cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00%");
  261.  
  262.                     cellStyle.SetFont(font);
  263.  
  264.                     break;
  265.  
  266.                 case stylexls.中文大写:
  267.  
  268.                     IDataFormat format1 = wb.CreateDataFormat();
  269.  
  270.                     cellStyle.DataFormat = format1.GetFormat("[DbNum2][$-804]0");
  271.  
  272.                     cellStyle.SetFont(font);
  273.  
  274.                     break;
  275.  
  276.                 case stylexls.科学计数法:
  277.  
  278.                     cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00E+00");
  279.  
  280.                     cellStyle.SetFont(font);
  281.  
  282.                     break;
  283.  
  284.                 case stylexls.默认:
  285.  
  286.                     cellStyle.SetFont(font);
  287.  
  288.                     break;
  289.  
  290.             }
  291.  
  292.             return cellStyle;
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.         }
  301.  
  302.         #endregion
  303.  
  304.        
  305.  
  306.         //从数据库读取数据写入到excel中
  307.  
  308.         private void btnwrite_Click(object sender, EventArgs e)
  309.  
  310.         {
  311.  
  312.             #region 创建数据库,表,设置单元的宽度
  313.  
  314.             //创建数据库
  315.  
  316.             IWorkbook wb = new HSSFWorkbook();
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.             //创建表
  328.  
  329.             ISheet sh = wb.CreateSheet("zhiyuan");
  330.  
  331.            
  332.  
  333.  
  334.  
  335.  
  336.             //设置单元的宽度
  337.  
  338.             sh.SetColumnWidth(0, 15 * 256);
  339.  
  340.             sh.SetColumnWidth(1, 35 * 256);
  341.  
  342.             sh.SetColumnWidth(2, 15 * 256);
  343.  
  344.             sh.SetColumnWidth(3, 10 * 256);
  345.  
  346.             #endregion
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.             int i = 0;
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.             #region 练习合并单元格
  363.  
  364.             sh.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 3));
  365.  
  366.             IRow row0 = sh.CreateRow(0);
  367.  
  368.             row0.Height = 20 * 20;
  369.  
  370.             ICell icell1top0 = row0.CreateCell(0);
  371.  
  372.             ICell icell1top1 = row0.CreateCell(1);
  373.  
  374.             ICell icell1top2 = row0.CreateCell(2);
  375.  
  376.             ICell icell1top3 = row0.CreateCell(3);
  377.  
  378.             icell1top0.CellStyle = Getcellstyle(wb, stylexls.);
  379.  
  380.             icell1top0.SetCellValue("标题合并单元");
  381.  
  382.             #endregion
  383.  
  384.  
  385.  
  386.  
  387.             i++;
  388.  
  389.  
  390.  
  391.  
  392.             #region 设置表头
  393.  
  394.             IRow row1 = sh.CreateRow(1);
  395.  
  396.             row1.Height = 20 * 20;
  397.  
  398.  
  399.  
  400.  
  401.             ICell icell1top = row1.CreateCell(0);
  402.  
  403.             icell1top.CellStyle = Getcellstyle(wb, stylexls.);
  404.  
  405.             icell1top.SetCellValue("网站名");
  406.  
  407.  
  408.  
  409.  
  410.             ICell icell2top = row1.CreateCell(1);
  411.  
  412.             icell2top.CellStyle = Getcellstyle(wb, stylexls.);
  413.  
  414.             icell2top.SetCellValue("网址");
  415.  
  416.  
  417.  
  418.  
  419.             ICell icell3top = row1.CreateCell(2);
  420.  
  421.             icell3top.CellStyle = Getcellstyle(wb, stylexls.);
  422.  
  423.             icell3top.SetCellValue("百度快照");
  424.  
  425.  
  426.  
  427.  
  428.             ICell icell4top = row1.CreateCell(3);
  429.  
  430.             icell4top.CellStyle = Getcellstyle(wb, stylexls.);
  431.  
  432.             icell4top.SetCellValue("百度收录");
  433.  
  434.             #endregion
  435.  
  436.  
  437.  
  438.  
  439.             i++;
  440.  
  441.  
  442.  
  443.  
  444.             #region 读取数据库写入表
  445.  
  446.             string sql = "select top 100 urlnam,url,bdtim,bdsl from zhiyuan";
  447.  
  448.             using (SqlDataReader dr = SqlHelper.ExecuteReaderText(sql, null))
  449.  
  450.             {
  451.  
  452.                 if (dr.HasRows)
  453.  
  454.                 {
  455.  
  456.                     while (dr.Read())
  457.  
  458.                     {
  459.  
  460.                         //创建行
  461.  
  462.                         IRow row = sh.CreateRow(i);
  463.  
  464.                         row.Height = 18 * 20;
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.                         //创建第1列
  473.  
  474.                         ICell icell = row.CreateCell(0);
  475.  
  476.                         icell.CellStyle = Getcellstyle(wb, stylexls.默认);
  477.  
  478.                         icell.SetCellValue(dr.GetValue(0).ToString());
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.                         //创建第2列
  487.  
  488.                         ICell icell1 = row.CreateCell(1);
  489.  
  490.                         icell1.CellStyle = Getcellstyle(wb, stylexls.url);
  491.  
  492.                         icell1.SetCellValue(dr.GetValue(1).ToString());
  493.  
  494.                         HSSFHyperlink link = new HSSFHyperlink(HyperlinkType.URL);
  495.  
  496.                         link.Address = (dr.GetValue(1).ToString());
  497.  
  498.                         icell1.Hyperlink = (link);
  499.  
  500.  
  501.  
  502.  
  503.                         //创建第3列
  504.  
  505.                         ICell icell2 = row.CreateCell(2);
  506.  
  507.                         icell2.CellStyle = Getcellstyle(wb, stylexls.时间);
  508.  
  509.                         icell2.SetCellValue(dr.IsDBNull(2) ? Convert.ToDateTime("1990-1-1") : dr.GetDateTime(2));
  510.  
  511.  
  512.  
  513.  
  514.                         //创建第4列
  515.  
  516.                         ICell icell3 = row.CreateCell(3);
  517.  
  518.                         icell3.CellStyle = Getcellstyle(wb, stylexls.默认);
  519.  
  520.                         icell3.SetCellValue(dr.IsDBNull(3) ? 0 : dr.GetInt32(3));
  521.  
  522.                         i++;
  523.  
  524.                     }
  525.  
  526.                 }
  527.  
  528.             }
  529.  
  530.             #endregion
  531.  
  532.            
  533.  
  534.            
  535.  
  536.             using (FileStream fs = File.OpenWrite("xxx.xls"))
  537.  
  538.             {
  539.  
  540.                 wb.Write(fs);
  541.  
  542.                 MessageBox.Show("Excel已经写入成功!");
  543.  
  544.             }
  545.  
  546.  
  547.  
  548.  
  549.         }
  550.  
  551.  
  552.  
  553.  
  554.         //这个函数可以不看。
  555.  
  556.         private void CreateRow(IRow row, int j, SqlDataReader dr, ICellStyle cellstyle)
  557.  
  558.         {
  559.  
  560.             if (dr.GetFieldType(j).Name == "Int32")
  561.  
  562.             {
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.                 row.CreateCell(j).SetCellValue(dr.IsDBNull(j) ? 0 : dr.GetInt32(j));
  571.  
  572.             }
  573.  
  574.             else if (dr.GetFieldType(j).Name == "Int16")
  575.  
  576.             { row.CreateCell(j).SetCellValue(dr.IsDBNull(j) ? 0 : dr.GetInt16(j)); }
  577.  
  578.             else if (dr.GetFieldType(j).Name == "Int64")
  579.  
  580.             { row.CreateCell(j).SetCellValue(dr.IsDBNull(j) ? 0 : dr.GetInt64(j)); }
  581.  
  582.             else if (dr.GetFieldType(j).Name == "String")
  583.  
  584.             { row.CreateCell(j).SetCellValue(dr.IsDBNull(j) ? "" : dr.GetString(j)); }
  585.  
  586.             else if (dr.GetFieldType(j).Name == "DateTime")
  587.  
  588.             {
  589.  
  590.  
  591.  
  592.  
  593.                 ICell cell = row.CreateCell(j);
  594.  
  595.                 cell.CellStyle = cellstyle;
  596.  
  597.                 cell.SetCellValue(dr.IsDBNull(j) ? Convert.ToDateTime("1990-1-1") : dr.GetDateTime(j));
  598.  
  599.  
  600.  
  601.  
  602.             }
  603.  
  604.             else if (dr.GetFieldType(j).Name == "Double")
  605.  
  606.             { row.CreateCell(j).SetCellValue(dr.IsDBNull(j) ? 0 : dr.GetDouble(j)); }
  607.  
  608.             else if (dr.GetFieldType(j).Name == "Byte[]")
  609.  
  610.             { row.CreateCell(j).SetCellValue(dr.IsDBNull(j) ? 0 : dr.GetByte(j)); }
  611.  
  612.             else if (dr.GetFieldType(j).Name == "Decimal")
  613.  
  614.             { row.CreateCell(j).SetCellValue(dr.IsDBNull(j) ? 0 : dr.GetDouble(j)); }
  615.  
  616.             else
  617.  
  618.             {
  619.  
  620.  
  621.  
  622.  
  623.                 row.CreateCell(j).SetCellValue(dr.IsDBNull(j) ? "" : dr.GetValue(j).ToString());
  624.  
  625.             }
  626.  
  627.  
  628.  
  629.  
  630.         }
  631.  
  632.  
  633.  
  634.  
  635.         #region 读取excel
  636.  
  637.         private void btnreade_Click(object sender, EventArgs e)
  638.  
  639.         {
  640.  
  641.             //先创建文件流
  642.  
  643.             if (DialogResult.OK == openFileDialog1.ShowDialog())
  644.  
  645.             {
  646.  
  647.                 using (FileStream fs = File.OpenRead(openFileDialog1.FileName))
  648.  
  649.                 {
  650.  
  651.                     //申明数据库对像
  652.  
  653.                     IWorkbook wk = new HSSFWorkbook(fs);
  654.  
  655.  
  656.  
  657.  
  658.                     //获取数据库中的每个表
  659.  
  660.                     for (int i = 0; i < wk.NumberOfSheets; i++)
  661.  
  662.                     {
  663.  
  664.                         //申明表
  665.  
  666.                         ISheet wk1 = wk.GetSheetAt(i);
  667.  
  668.  
  669.  
  670.  
  671.                         txtout.AppendText("====================" + wk1.SheetName + "================\r\n");
  672.  
  673.  
  674.  
  675.  
  676.                         //获取表的行
  677.  
  678.                         for (int j = 0; j < wk1.LastRowNum + 1; j++)
  679.  
  680.                         {
  681.  
  682.                             //申明行
  683.  
  684.                             IRow row = wk1.GetRow(j);
  685.  
  686.                             for (int k = 0; k < row.LastCellNum + 1; k++)
  687.  
  688.                             {
  689.  
  690.                                 txtout.AppendText(string.Format("{0}\t", row.GetCell(k) == null ? "" : row.GetCell(k).ToString()));
  691.  
  692.                             }
  693.  
  694.                             txtout.AppendText("\r\n");
  695.  
  696.                         }
  697.  
  698.                     }
  699.  
  700.  
  701.  
  702.  
  703.                 }
  704.  
  705.             }
  706.  
  707.  
  708.  
  709.  
  710.         }
  711.  
  712.         #endregion
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.         #region 把excel转成htm
  721.  
  722.         private void button1_Click(object sender, EventArgs e)
  723.  
  724.         {
  725.  
  726.             if (DialogResult.OK == openFileDialog1.ShowDialog())
  727.  
  728.             {
  729.  
  730.                 string str = htmlxsl.Gethtmlxls(openFileDialog1.FileName);
  731.  
  732.                 using (FileStream fs = File.OpenWrite("1.htm"))
  733.  
  734.                 {
  735.  
  736.                     byte[] b = Encoding.Default.GetBytes(str);
  737.  
  738.                     fs.Write(b, 0, b.Length);
  739.  
  740.                 }
  741.  
  742.             }
  743.  
  744.         }
  745.  
  746.         #endregion
  747.  
  748.        
  749.  
  750.     }
  751.  
  752. }
  753.  
  754.  
  755.  
  756. 生成htm的类
  757.  
  758.  
  759. using System.Text;
  760.  
  761. using NPOI.HSSF.UserModel;
  762.  
  763. using NPOI.HPSF;
  764.  
  765. using NPOI.POIFS.FileSystem;
  766.  
  767. using NPOI.HSSF.Util;
  768.  
  769. using NPOI.SS.UserModel;
  770.  
  771. using System.IO;
  772.  
  773. using SqlHelPerXHC;
  774.  
  775. using NPOI.HSSF.Record.CF;
  776.  
  777. namespace Excl
  778.  
  779. {
  780.  
  781.     public static class htmlxsl
  782.  
  783.     {
  784.  
  785.         private static ISheet sht;
  786.  
  787.         public static string Gethtmlxls(string path)
  788.  
  789.         {
  790.  
  791.  
  792.  
  793.  
  794.             IWorkbook wb = new HSSFWorkbook(new FileStream(path, FileMode.Open));
  795.  
  796.             sht = wb.GetSheet("zhiyuan");
  797.  
  798.             //取行Excel的最大行数    
  799.  
  800.             int rowsCount = sht.LastRowNum;
  801.  
  802.             //为保证Table布局与Excel一样,这里应该取所有行中的最大列数(需要遍历整个Sheet)。    
  803.  
  804.             //为少一交全Excel遍历,提高性能,我们可以人为把第0行的列数调整至所有行中的最大列数。    
  805.  
  806.             int colsCount = sht.GetRow(0).LastCellNum;
  807.  
  808.             int colSpan;
  809.  
  810.             int rowSpan;
  811.  
  812.             bool isByRowMerged;
  813.  
  814.             StringBuilder table = new StringBuilder(rowsCount * 32);
  815.  
  816.             table.Append("<table border='1px'>");
  817.  
  818.             for (int rowIndex = 0; rowIndex < rowsCount; rowIndex++)
  819.  
  820.             {
  821.  
  822.                 table.Append("<tr>");
  823.  
  824.                 for (int colIndex = 0; colIndex < colsCount; colIndex++)
  825.  
  826.                 {
  827.  
  828.                     GetTdMergedInfo(rowIndex, colIndex, out colSpan, out rowSpan, out isByRowMerged);
  829.  
  830.                     //如果已经被行合并包含进去了就不输出TD了。            
  831.  
  832.                     //注意被合并的行或列不输出的处理方式不一样,见下面一处的注释说明了列合并后不输出TD的处理方式。
  833.  
  834.                     if (isByRowMerged)
  835.  
  836.                     {
  837.  
  838.                         continue;
  839.  
  840.                     }
  841.  
  842.                     table.Append("<td");
  843.  
  844.                     if (colSpan > 1)
  845.  
  846.                         table.Append(string.Format(" colSpan={0}", colSpan));
  847.  
  848.                     if (rowSpan > 1)
  849.  
  850.                         table.Append(string.Format(" rowSpan={0}", rowSpan));
  851.  
  852.                     table.Append(">");
  853.  
  854.                     table.Append(sht.GetRow(rowIndex).GetCell(colIndex));
  855.  
  856.                     //列被合并之后此行将少输出colSpan-1个TD。            
  857.  
  858.                     if (colSpan > 1)
  859.  
  860.                         colIndex += colSpan - 1;
  861.  
  862.                     table.Append("</td>");
  863.  
  864.                 }
  865.  
  866.                 table.Append("</tr>");
  867.  
  868.             }
  869.  
  870.             table.Append("</table>");
  871.  
  872.             return table.ToString();
  873.  
  874.  
  875.  
  876.  
  877.         }
  878.  
  879.         /// <summary>
  880.  
  881.         ///  获取Table某个TD合并的列数和行数等信息。与Excel中对应Cell的合并行数和列数一致。
  882.  
  883.         /// </summary>
  884.  
  885.         /// <param name="rowIndex">行号</param>
  886.  
  887.         /// <param name="colIndex">列号</param>
  888.  
  889.         ///  <param name="colspan">TD中需要合并的行数</param>
  890.  
  891.         /// <param name="rowspan">TD中需要合并的列数</param>
  892.  
  893.         /// <param name="rowspan">此单元格是否被某个行合并包含在内。如果被包含在内,将不输出TD。</param>
  894.  
  895.         /// <returns></returns>
  896.  
  897.         private static void GetTdMergedInfo(int rowIndex, int colIndex, out int colspan, out int rowspan, out bool isByRowMerged)
  898.  
  899.         {
  900.  
  901.             colspan = 1;
  902.  
  903.             rowspan = 1;
  904.  
  905.             isByRowMerged = false;
  906.  
  907.             int regionsCuont = sht.NumMergedRegions;
  908.  
  909.            
  910.  
  911.             NPOI.SS.Util.CellRangeAddress region;
  912.  
  913.                
  914.  
  915.             for (int i = 0; i < regionsCuont; i++)
  916.  
  917.             {
  918.  
  919.                
  920.  
  921.                 region = sht.GetMergedRegion(i);
  922.  
  923.  
  924.  
  925.  
  926.                 if (region.FirstRow == rowIndex && region.FirstColumn == colIndex)
  927.  
  928.                 {
  929.  
  930.                     colspan = region.LastColumn - region.FirstColumn + 1;
  931.  
  932.                     rowspan = region.LastRow - region.FirstRow + 1;
  933.  
  934.                     return;
  935.  
  936.                 }
  937.  
  938.                 else if (rowIndex > region.FirstRow && rowIndex <= region.LastRow && colIndex >= region.FirstColumn && colIndex <= region.LastColumn)
  939.  
  940.                 {
  941.  
  942.                     isByRowMerged = true;
  943.  
  944.                 }
  945.  
  946.             }
  947.  
  948.         }
  949.  
  950.     }
  951.  
  952. }

Reply to "NPOI. DLL usage. Cell, style, font, color, row height, width. Reading and writing Excel"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website