/// <summary>
 /// 初始化样式
 /// </summary>
 /// <param name="style"></param>
 public void InitializeStyle(HSSFCellStyle style)
 {
     if (style == null)
     {
         style = (HSSFCellStyle)Hssfworkbook.CreateCellStyle();
     }
 }
Example #2
0
        private static void CreateExcelForCommonIp(List <OrtakIp> dublicateIp, string outputPath)
        {
            ISheet sheet1 = Hssfworkbook.CreateSheet("Duplicate Ip");

            sheet1.DefaultColumnWidth = 50;

            IFont font1 = Hssfworkbook.CreateFont();

            font1.Color              = HSSFColor.Blue.Index;
            font1.Boldweight         = (short)FontBoldWeight.Bold;
            font1.FontHeightInPoints = 10;

            ICellStyle headerstyle = Hssfworkbook.CreateCellStyle();

            headerstyle.SetFont(font1);

            IRow hrow       = sheet1.CreateRow(0);
            var  headerList = new List <string>()
            {
                "Name", "Id", "Ip"
            };

            for (int i = 0; i < headerList.Count(); i++)
            {
                hrow.CreateCell(i).SetCellValue(headerList.ElementAt(i) == null ? "NULL" : headerList.ElementAt(i));
                hrow.GetCell(i).CellStyle = headerstyle;
            }

            var rowCount = 1;

            for (int i = 0; i < dublicateIp.Count(); i++)
            {
                IRow row    = sheet1.CreateRow(rowCount++);
                var  values = new[] { dublicateIp.ElementAt(i).Name, dublicateIp.ElementAt(i).Id, dublicateIp.ElementAt(i).Ip };

                for (int j = 0; j < values.Count(); j++)
                {
                    row.CreateCell(j).SetCellValue(values.ElementAt(j) == string.Empty ? "NULL" : values.ElementAt(j));
                }
            }
            using (var fs = new FileStream(outputPath, FileMode.OpenOrCreate, FileAccess.Write))
            {
                Hssfworkbook.Write(fs);
            }
        }