npoi 添加 xls页眉页脚重复标题页码

npoi 添加 xls页眉页脚重复标题页码

private static void TestHyf()
        {
            IWorkbook book = new HSSFWorkbook();
            ISheet sheet = book.CreateSheet("test");
            ICellStyle cellStyle = book.CreateCellStyle();
            cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
            cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
            cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
            cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
            IRow row = sheet.CreateRow(0);
            for (int i = 0; i < 5; i++)
            {
                ICell cell = row.CreateCell(i);
                cell.SetCellValue("col" + i);
            }
            for (int i = 1; i < 10000; i++)
            {
                IRow rowtemp = sheet.CreateRow(i);
                for (int j = 0; j < 5; j++)
                {
                    ICell cell = rowtemp.CreateCell(j);
                    cell.SetCellValue(i * j);
                    cell.CellStyle = cellStyle;
                }
            }
            sheet.FitToPage = false;
            sheet.RepeatingRows = new CellRangeAddress(0, 0, 0, 5);
            sheet.Header.Center = "testtop";
            sheet.Footer.Center = "testfooter";
            sheet.Footer.Right="第 &P 页,共 &N 页";//&P当前页码&N总页码数
            using (FileStream fs = File.OpenWrite(@"c:/myxls.xls"))
                book.Write(fs);
            MessageBox.Show("提示:创建成功!");

        }

posted on 2016-07-22 10:59  fendoudexiaoniao  阅读(691)  评论(0编辑  收藏  举报

导航