Exemplo n.º 1
0
        /// <summary>
        /// Set the font for this style
        /// </summary>
        /// <param name="font">a font object Created or retreived from the HSSFWorkbook object</param>
        public void SetFont(NPOI.SS.UserModel.Font font)
        {
            format.IsIndentNotParentFont = (true);
            short fontindex = font.Index;

            format.FontIndex = (fontindex);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 单元格的字体样式(宋体,12号)
 /// </summary>
 /// <returns></returns>
 public NPOI.SS.UserModel.Font cellFont()
 {
     NPOI.SS.UserModel.Font cellsFont = hssfworkbook.CreateFont();
     cellsFont.FontHeightInPoints = 12;
     cellsFont.FontName           = "宋体";
     return(cellsFont);
 }
Exemplo n.º 3
0
        private void font_color(HSSFWorkbook hssfworkbook, Cell cell, short color)
        {
            CellStyle cellStyleFontColor = hssfworkbook.CreateCellStyle();

            NPOI.SS.UserModel.Font font1 = hssfworkbook.CreateFont();
            font1.Color = color;
            cellStyleFontColor.SetFont(font1);
            cell.CellStyle = cellStyleFontColor;
        }
Exemplo n.º 4
0
 private void SetBold(Cell cell, CellStyle style)
 {
     if (cell.IsBold)
     {
         Font font = sheet.Workbook.CreateFont();
         font.Boldweight = (short)FontBoldWeight.BOLD;
         style.SetFont(font);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 右对齐数字格式
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        public static CellStyle GetRightDataCellStyle(NPOI.SS.UserModel.Cell cell)
        {
            if (rightDataCellStyle == null)
            {
                CellStyle style = cell.Sheet.Workbook.CreateCellStyle();
                style.BorderBottom = CellBorderType.THIN;
                style.BorderLeft   = CellBorderType.THIN;
                style.BorderRight  = CellBorderType.THIN;
                style.BorderTop    = CellBorderType.THIN;
                style.Alignment    = NPOI.SS.UserModel.HorizontalAlignment.RIGHT;
                NPOI.SS.UserModel.Font font = cell.Sheet.Workbook.CreateFont();
                font.FontHeightInPoints = 9;
                style.SetFont(font);
                style.DataFormat   = cell.Sheet.Workbook.CreateDataFormat().GetFormat("_ * #,##0.00_ ;_ * -#,##0.00_ ;_ * \" - \"??_ ;_ @_ ");
                rightDataCellStyle = style;
            }

            return(rightDataCellStyle);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 居中对齐加粗格式
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        public static CellStyle GetCenterBoldCellStyle(NPOI.SS.UserModel.Cell cell)
        {
            if (centerBoldCellStyle == null)
            {
                CellStyle style = cell.Sheet.Workbook.CreateCellStyle();
                style.BorderBottom      = CellBorderType.THIN;
                style.BorderLeft        = CellBorderType.THIN;
                style.BorderRight       = CellBorderType.THIN;
                style.BorderTop         = CellBorderType.THIN;
                style.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
                style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;
                NPOI.SS.UserModel.Font font = cell.Sheet.Workbook.CreateFont();
                font.FontHeightInPoints = 10;
                font.Boldweight         = (short)FontBoldWeight.BOLD;
                style.SetFont(font);
                centerBoldCellStyle = style;
            }

            return(centerBoldCellStyle);
        }
Exemplo n.º 7
0
        public void ExportarListaNegra(DataTable blackList, string caminhoSalvar)
        {
            doc = new HSSFWorkbook();

            try
            {
                Sheet planilha = doc.CreateSheet();

                CellStyle estilo = doc.CreateCellStyle();
                estilo.Alignment           = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
                estilo.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.ROYAL_BLUE.index;
                estilo.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.ROYAL_BLUE.index;
                estilo.FillPattern         = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;

                NPOI.SS.UserModel.Font fonte = doc.CreateFont();
                fonte.Boldweight         = (short)NPOI.SS.UserModel.FontBoldWeight.BOLD;
                fonte.FontName           = "Arial";
                fonte.FontHeightInPoints = 16;
                fonte.Color = NPOI.HSSF.Util.HSSFColor.WHITE.index;
                estilo.SetFont(fonte);

                Row linha = planilha.CreateRow(0);
                linha.HeightInPoints = 22;
                Cell celula = linha.CreateCell(0);
                celula.CellStyle = estilo;
                celula.SetCellValue(blackList.Rows[0][0].ToString());
                planilha.AddMergedRegion(new CellRangeAddress(0, 0, 0, 8));

                //pula 1 linha
                int linhaInicial = 2;

                //ignora a coluna com o nome do evento
                int colunaInicial = 1;

                GerarPlanilhaNPOI(blackList, caminhoSalvar, planilha, linhaInicial, colunaInicial);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 创建电影排片信息字段
        /// </summary>
        /// <param name="row"></param>
        /// <param name="style"></param>
        /// <param name="info"></param>
        private void SetCellMovieInfo(Row row, CellStyle style, IMovieShowList.MovieShow info)
        {
            CellStyle styleLeft = cellLeftAllBorder();

            NPOI.SS.UserModel.Font font = cellFont();

            Cell cellth = row.CreateCell(0);

            cellth.SetCellValue(info.Room);
            cellth.CellStyle = style;


            Cell bt = row.CreateCell(1);

            bt.SetCellValue(info.BeginTime);
            bt.CellStyle = style;


            //散场时间
            Cell cellend = row.CreateCell(2);

            cellend.SetCellValue(info.EndTime);
            cellend.CellStyle = style;


            Cell cellname = row.CreateCell(3);

            cellname.SetCellValue(info.Name);
            cellname.CellStyle = styleLeft;



            Cell cellVersion = row.CreateCell(4);

            cellVersion.CellStyle = styleLeft;
            cellVersion.SetCellValue(info.Version);
            Cell celly = row.CreateCell(5);

            celly.CellStyle = styleLeft;
            celly.SetCellValue(info.Language);
        }
Exemplo n.º 9
0
        private void GerarHeadersNPOI(DataTable tabela, Sheet planilha, ref int linhaInicial, int colunaInicial)
        {
            try
            {
                Row  linha;
                Cell celula;

                NPOI.SS.UserModel.Font fonteCabecalho = doc.CreateFont();
                fonteCabecalho.FontName           = "Arial";
                fonteCabecalho.Color              = NPOI.HSSF.Util.HSSFColor.WHITE.index;
                fonteCabecalho.FontHeightInPoints = 10;
                fonteCabecalho.Boldweight         = (short)NPOI.SS.UserModel.FontBoldWeight.BOLD;

                CellStyle estiloCabecalho = doc.CreateCellStyle();
                estiloCabecalho.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.ROYAL_BLUE.index;
                estiloCabecalho.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.ROYAL_BLUE.index;
                estiloCabecalho.FillPattern         = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;
                estiloCabecalho.SetFont(fonteCabecalho);
                estiloCabecalho.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;

                linha = planilha.CreateRow(linhaInicial);

                for (int colunaDt = colunaInicial, colunaPlan = 0; colunaDt < tabela.Columns.Count; colunaDt++, colunaPlan++)
                {
                    DataColumn cabecalho = tabela.Columns[colunaDt];
                    celula           = linha.CreateCell(colunaPlan, CellType.STRING);
                    celula.CellStyle = estiloCabecalho;
                    celula.SetCellValue(cabecalho.ColumnName);
                }

                linhaInicial++;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 设置第一行的表头
        /// </summary>
        /// <param name="sheet"></param>
        private void CreateR1(Sheet sheet, int firstRow, int lastRow, int firstCol, int lastCol, string value)
        {
            //创建字体样式第一行表头大标题
            NPOI.SS.UserModel.Font fontHeader = hssfworkbook.CreateFont();
            //fontHeader.FontHeight = 22 * 22;
            fontHeader.FontHeightInPoints = 16;
            fontHeader.Boldweight         = 700;


            //创建第一行表头
            Row rowHeader = sheet.CreateRow(0);

            rowHeader.RowStyle       = SetCellAllCenterNoBorder();
            rowHeader.HeightInPoints = 32;

            Cell cellHeader = rowHeader.CreateCell(0);

            cellHeader.SetCellValue(value);
            cellHeader.CellStyle = SetCellAllCenterNoBorder();
            cellHeader.CellStyle.SetFont(fontHeader);

            //将表头跨列合并
            sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(firstRow, lastRow, firstCol, lastCol));
        }
Exemplo n.º 11
0
        //public void Create()
        //{
        //    HSSFWorkbook book = new HSSFWorkbook();
        //    ISheet sheet = book.CreateSheet("Sheet1");

        //    IRow row = sheet.CreateRow(20);//index代表多少行
        //    row.HeightInPoints = 35;//行高
        //    ICell cell = row.CreateCell(0);//创建第一列
        //    cell.SetCellValue("设置单元格的值");



        //}

        /// <summary>
        /// 导出基本操作示例方法
        /// </summary>
        public static void ExportExcel()
        {
            //初始化一个新的HSSFWorkbook实例
            HSSFWorkbook hssfworkbook = new HSSFWorkbook();

            //设置excel必须的文件属性(该属性用来存储 如作者、标题、标记、备注、主题等信息,右键可查看的属性信息)
            DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();

            dsi.Company = "NPOI Team";
            SummaryInformation si = PropertySetFactory.CreateSummaryInformation();

            si.Subject = "NPOI SDK Example";
            hssfworkbook.DocumentSummaryInformation = dsi;
            hssfworkbook.SummaryInformation         = si;


            //新建一个Workbook默认都会新建3个Sheet(标准的Excel文件有3个Sheet)。所以必须加入下面的创建Sheet的代码才能保证生成的文件正常
            HSSFSheet sheet = (HSSFSheet)hssfworkbook.CreateSheet("new sheet");
            // hssfworkbook.CreateSheet("Sheet1");
            // hssfworkbook.CreateSheet("Sheet2");
            // hssfworkbook.CreateSheet("Sheet3");

            //建创行
            Row row1 = sheet.CreateRow(0);

            //建单元格,比如创建A1位置的单元格:
            row1.Height = 500;
            CellStyle s = hssfworkbook.CreateCellStyle();

            s.FillForegroundColor = HSSFColor.LIGHT_GREEN.index;
            s.FillPattern         = FillPatternType.SOLID_FOREGROUND;

            //第一列
            Cell cell1 = row1.CreateCell(0);

            cell1.CellStyle = s;

            Font font = hssfworkbook.CreateFont();

            font.FontName           = "宋体";
            font.FontHeightInPoints = 20;
            //设置字体加粗样式
            font.Boldweight = (short)FontBoldWeight.BOLD;
            cell1.CellStyle.SetFont(font);
            cell1.CellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
            cell1.SetCellValue("《大明宫保护办月报月计划》——( 行政管理部)6月工作计划");
            cell1.CellStyle.BorderBottom = CellBorderType.THIN;
            cell1.CellStyle.BorderLeft   = CellBorderType.THIN;
            cell1.CellStyle.BorderRight  = CellBorderType.THIN;
            cell1.CellStyle.BorderTop    = CellBorderType.THIN;

            sheet.SetColumnWidth(0, 4 * 256);
            //第二列
            Cell cell2 = row1.CreateCell(1);

            cell2.CellStyle = s;
            sheet.SetColumnWidth(1, 12 * 256);
            //第三列
            Cell cell3 = row1.CreateCell(2);

            cell3.CellStyle = s;
            sheet.SetColumnWidth(2, 20 * 256);
            //第四列
            Cell cell4 = row1.CreateCell(3);

            cell4.CellStyle = s;
            sheet.SetColumnWidth(3, 25 * 256);
            //第五列
            Cell cell5 = row1.CreateCell(4);

            cell5.CellStyle = s;
            sheet.SetColumnWidth(4, 35 * 256);
            //第六列
            Cell cell6 = row1.CreateCell(5);

            cell6.CellStyle = s;
            sheet.SetColumnWidth(5, 20 * 256);
            //第七列
            Cell cell7 = row1.CreateCell(6);

            cell7.CellStyle = s;
            sheet.SetColumnWidth(6, 20 * 256);
            //第八列
            Cell cell8 = row1.CreateCell(7);

            cell8.CellStyle = s;
            sheet.SetColumnWidth(7, 20 * 256);
            //第9列
            Cell cell9 = row1.CreateCell(8);

            cell9.CellStyle = s;
            sheet.SetColumnWidth(8, 20 * 256);

            //第10列
            Cell cell10 = row1.CreateCell(9);

            cell10.CellStyle = s;
            sheet.SetColumnWidth(9, 20 * 256);

            //第11列
            Cell cell11 = row1.CreateCell(10);

            cell11.CellStyle = s;
            sheet.SetColumnWidth(10, 20 * 256);

            CellRangeAddress r = new CellRangeAddress(0, 0, 0, 10);

            sheet.AddMergedRegion(r);
            //sheet.AddMergedRegion(new NPOI.SS.Util.Region(0, 0, 0, 10));


            CreateRow2(hssfworkbook, sheet);

            CreateRow3_4(hssfworkbook, sheet);

            _1stModule _1StModule = new _1stModule()
            {
                _1stModuleName = "管理工作"
            };

            List <_2ndModule> _2NdModules = new List <_2ndModule>();
            _2ndModule        _2NdModule  = new _2ndModule {
                _2ndModuleName = "与战略地图要求相关"
            };
            DataItem item = new DataItem
            {
                Work           = "保护办十年工作总结",
                Result         = "30日前完成保护办十年工作总结(总结部分)",
                _1stWeek       = "根据主要领导意见进行修改",
                _2ndWeek       = "进行修改",
                _3rdWeek       = "进行修改",
                _4thWeek       = "完成总结",
                PersonInCharge = "雷博",
                Penaty         = "50"
            };

            _2NdModule.datas = new List <DataItem>();
            _2NdModule.datas.Add(item);
            _2NdModules.Add(_2NdModule);

            _2NdModule = new _2ndModule {
                _2ndModuleName = "与制度、流程、标准、工具相关"
            };
            _2NdModule.datas = new List <DataItem>();
            _2NdModules.Add(_2NdModule);
            _2NdModule = new _2ndModule {
                _2ndModuleName = "与企业文化相关"
            };
            _2NdModule.datas = new List <DataItem>();
            _2NdModules.Add(_2NdModule);
            _2NdModule = new _2ndModule {
                _2ndModuleName = "与团队建设相关"
            };
            item = new DataItem
            {
                Work           = "组织公文写作培训",
                Result         = "30日前完成培训",
                _1stWeek       = "",
                _2ndWeek       = "与培训老师确定时间和内容",
                _3rdWeek       = "与培训老师确定时间和内容",
                _4thWeek       = "完成培训",
                PersonInCharge = "王倩",
                Penaty         = "50"
            };
            _2NdModule.datas = new List <DataItem>();
            _2NdModule.datas.Add(item);
            _2NdModules.Add(_2NdModule);

            _1StModule._2ndModules = _2NdModules;

            CreateRowsByModules(_1StModule, sheet, hssfworkbook);


            //把这个HSSFWorkbook实例写入文件
            FileStream file = new FileStream("Example1.xls", FileMode.Create);

            hssfworkbook.Write(file);
            file.Close();
        }
Exemplo n.º 12
0
        private static void CreateRow3_4(HSSFWorkbook hssfworkbook, HSSFSheet sheet)
        {
            Font font = hssfworkbook.CreateFont();

            font.FontName           = "宋体";
            font.FontHeightInPoints = 12;
            //设置字体加粗样式
            font.Boldweight = (short)FontBoldWeight.BOLD;

            CellStyle style = hssfworkbook.CreateCellStyle();

            //设置边框
            style.BorderTop    = CellBorderType.THIN;
            style.BorderBottom = CellBorderType.THIN;
            style.BorderLeft   = CellBorderType.THIN;
            style.BorderRight  = CellBorderType.THIN;
            //设置单元格的样式:水平对齐居中
            style.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
            style.VerticalAlignment = VerticalAlignment.CENTER;

            style.FillForegroundColor = HSSFColor.LIGHT_GREEN.index;
            style.FillPattern         = FillPatternType.SOLID_FOREGROUND;
            //使用SetFont方法将字体样式添加到单元格样式中
            style.SetFont(font);

            //建创行
            Row row2 = sheet.CreateRow(2);

            string[] strs = new string[] { "NO", "一级模块", "二级模块", "工作\n安排", "结果定义" };
            for (int i = 0; i < strs.Length; i++)
            {
                Cell cell = row2.CreateCell(i);
                //cell.CellStyle.SetFont(font);
                cell.SetCellValue(strs[i]);
                cell.CellStyle = style;
            }

            var newcell = row2.CreateCell(5);

            newcell.CellStyle = style;
            newcell.SetCellValue("过程节点和完成时间");
            newcell = row2.CreateCell(6);
            newcell = row2.CreateCell(7);
            newcell = row2.CreateCell(8);
            sheet.AddMergedRegion(new NPOI.SS.Util.Region(2, 5, 2, 8));

            newcell           = row2.CreateCell(9);
            newcell.CellStyle = style;
            newcell.SetCellValue("责任人");

            newcell           = row2.CreateCell(10);
            newcell.CellStyle = style;
            newcell.SetCellValue("自罚承诺");

            Row row3 = sheet.CreateRow(3);

            string[] strs2 = new string[] { "", "", "", "", "可衡量、有价值、看得见、摸得着", "第一周", "第二周", "第三周", "第四周", "", "" };

            for (int i = 0; i < strs2.Length; i++)
            {
                Cell cell = row3.CreateCell(i);
                //cell.CellStyle.SetFont(font);
                cell.SetCellValue(strs2[i]);
                cell.CellStyle = style;
            }

            sheet.AddMergedRegion(new NPOI.SS.Util.Region(2, 0, 3, 0));
            sheet.AddMergedRegion(new NPOI.SS.Util.Region(2, 1, 3, 1));
            sheet.AddMergedRegion(new NPOI.SS.Util.Region(2, 2, 3, 2));
            sheet.AddMergedRegion(new NPOI.SS.Util.Region(2, 3, 3, 3));
            sheet.AddMergedRegion(new NPOI.SS.Util.Region(2, 9, 3, 9));
            sheet.AddMergedRegion(new NPOI.SS.Util.Region(2, 10, 3, 10));
        }
Exemplo n.º 13
0
        private static void CreateRowsByModules(_1stModule module, HSSFSheet sheet, HSSFWorkbook hssfworkbook)
        {
            int offset = 4;

            for (int i = 0; i < module._2ndModules.Count; i++)
            {
                for (int j = 0; j < module._2ndModules[i].datas.Count; j++)
                {
                    offset++;
                    Row row2 = sheet.CreateRow(offset);

                    Font font = hssfworkbook.CreateFont();
                    font.FontName           = "宋体";
                    font.FontHeightInPoints = 12;
                    //设置字体加粗样式
                    font.Boldweight = (short)FontBoldWeight.BOLD;

                    CellStyle style = hssfworkbook.CreateCellStyle();
                    //设置边框
                    style.BorderTop    = CellBorderType.THIN;
                    style.BorderBottom = CellBorderType.THIN;
                    style.BorderLeft   = CellBorderType.THIN;
                    style.BorderRight  = CellBorderType.THIN;
                    style.WrapText     = true;
                    //设置单元格的样式:水平对齐居中
                    style.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
                    style.VerticalAlignment = VerticalAlignment.CENTER;

                    style.FillForegroundColor = HSSFColor.LIGHT_GREEN.index;
                    style.FillPattern         = FillPatternType.SOLID_FOREGROUND;
                    //使用SetFont方法将字体样式添加到单元格样式中
                    style.SetFont(font);

                    var cell = row2.CreateCell(3);
                    cell.SetCellValue(module._2ndModules[i].datas[j].Work);
                    cell.CellStyle = style;

                    cell = row2.CreateCell(4);
                    cell.SetCellValue(module._2ndModules[i].datas[j].Result);
                    cell.CellStyle = style;

                    cell = row2.CreateCell(5);
                    cell.SetCellValue(module._2ndModules[i].datas[j]._1stWeek);
                    cell.CellStyle = style;

                    cell = row2.CreateCell(6);
                    cell.SetCellValue(module._2ndModules[i].datas[j]._2ndWeek);
                    cell.CellStyle = style;

                    cell = row2.CreateCell(7);
                    cell.SetCellValue(module._2ndModules[i].datas[j]._3rdWeek);
                    cell.CellStyle = style;

                    cell = row2.CreateCell(8);
                    cell.SetCellValue(module._2ndModules[i].datas[j]._4thWeek);
                    cell.CellStyle = style;

                    cell = row2.CreateCell(9);
                    cell.SetCellValue(module._2ndModules[i].datas[j].PersonInCharge);
                    cell.CellStyle = style;

                    cell = row2.CreateCell(10);
                    cell.SetCellValue(module._2ndModules[i].datas[j].Penaty);
                    cell.CellStyle = style;
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// 放映表导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 放映表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //创建排片信息集合对象,用以保存信息
            List <IMovieShowList.MovieShow> listMovie = new List <IMovieShowList.MovieShow>();

            try
            {
                if (newExcel)
                {
                    ExcelSource ex = new ExcelSource();
                    listMovie = ex.GetList4Excel(newFileName);
                    if (!ex.isOk)
                    {
                        MessageBox.Show(ex.Msg);
                        return;
                    }
                }
                else
                {
                    //排片信息读取
                    listMovie = movieList;
                }


                if (listMovie.Count == 0)
                {
                    MessageBox.Show("没有排片信息");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("未知错误,请重试");
                return;
            }

            MovieEndTime end = new MovieEndTime();

            listMovie = end.GetMovieEndTimeList(listMovie);
            string headeValue = string.Empty;

            //是否Excel源或Api源
            bool ok = IsExcelOrApi(out headeValue, listMovie);

            if (!ok)
            {
                return;
            }


            //让排片信息以厅号来排序
            var iList = listMovie.OrderBy(i => i.Room[0]);

            //提取所有厅号
            var a = from room in iList select room.Room;

            //去重之后放映厅的集合
            List <string> RoomInfo = a.Distinct().ToList();

            //创建放映表
            hssfworkbook = new HSSFWorkbook();

            Sheet sheet = hssfworkbook.CreateSheet("放映表");

            sheet.PrintSetup.Landscape = true;//设置为横向


            //设定列宽
            for (int i = 0; i < 12; i++)
            {
                if ((i + 1) % 3 == 0)
                {
                    //将包含电影名称的列设置列宽
                    sheet.SetColumnWidth(i, 23 * 256 + 200);
                }
                else
                {
                    //其它的列设置列宽
                    sheet.SetColumnWidth(i, 6 * 256 + 200);
                }
            }


            //创建第一行
            CreateR1(sheet, 0, 0, 0, 11, headeValue);

            //行标识从第2行开始
            int roomCout = 1;
            Dictionary <string, int> roomIndex = new Dictionary <string, int>();

            //创建当前行
            Row row = sheet.CreateRow(roomCout);

            row.HeightInPoints = 30;

            int j = -1;
            //保存厅号的位置信息
            List <Cell> listCell = new List <Cell>();

            //创建其它字段
            for (int i = 0; i < RoomInfo.Count; i++)
            {
                //创建第四个厅的时候转折
                if ((i + 1) % 5 == 0)
                {
                    //并且前面空余8格
                    roomCout          += 9;
                    row                = sheet.CreateRow(roomCout);
                    row.HeightInPoints = 30;
                    j = -1;
                }
                j++;
                //创建单元格
                //创建字体样式
                NPOI.SS.UserModel.Font fontHeader = hssfworkbook.CreateFont();
                fontHeader.FontHeightInPoints = 12;
                fontHeader.Boldweight         = 700;

                int  count = j * 3;
                Cell cell  = row.CreateCell(count);
                cell.SetCellValue(RoomInfo[i]);
                cell.CellStyle = SetCellAllCenterBorder();
                cell.CellStyle.SetFont(fontHeader);
                //将后面的两个单元格设置出来
                SetCell(row, count + 1, string.Empty);
                SetCell(row, count + 2, string.Empty);
                //进行单元格合并
                sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(roomCout, roomCout, count, count + 2));


                listCell.Add(cell);
            }

            //将影片信息按厅排列
            List <IMovieShowList.MovieShow> li = listMovie.OrderBy(x => x.Room[0]).ToList <IMovieShowList.MovieShow>();


            int rowIndex = 0;
            int indexCol;

            foreach (var item in listCell)
            {
                //当前厅名
                string room = item.StringCellValue;
                //找到当前厅的所有子集并且进行排序
                List <IMovieShowList.MovieShow> s = (from i in li where i.Room == room select i).OrderBy(x => x.BeginTime).ToList <IMovieShowList.MovieShow>();
                //如果rowIndex与上次一致,则不创建行,直接在原有的行上创建单元格
                //保存之前的rowIndex;

                rowIndex = item.RowIndex + 1; //3

                indexCol = item.ColumnIndex;  //0

                //循环子集添加
                foreach (var movie in s)
                {
                    //获得下一行
                    Row rowCell = sheet.GetRow(rowIndex) ?? sheet.CreateRow(rowIndex);
                    //设置行高
                    rowCell.HeightInPoints = 20;
                    //在行下面创建三个单元格填充值
                    SetCell(rowCell, indexCol, movie.BeginTime);
                    SetCell(rowCell, indexCol + 1, movie.EndTime);

                    //单独处理电影名称,让其左对齐
                    //SetCell(rowCell, indexCol+2, movie.Name);
                    Cell cellName = rowCell.CreateCell(indexCol + 2);
                    cellName.CellStyle = cellLeftAllBorder();
                    cellName.SetCellValue(movie.Name);
                    rowIndex++;
                }
            }

            //打开一个保存对话框,让用户保存数据
            SaveFileDialog save = new SaveFileDialog();

            save.Filter   = "excel|*.xls";
            save.FileName = headeValue + "--放映 ";
            DialogResult res = save.ShowDialog();

            if (res == DialogResult.OK)
            {
                string path = save.FileName;
                try
                {
                    FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write);
                    hssfworkbook.Write(file);
                    file.Close();
                    MessageBox.Show("保存成功");
                }
                catch
                {
                    MessageBox.Show("文件已打开,请先关闭文件");
                    return;
                }
            }
            else
            {
                return;
            }
        }