NPOI 1.2.3教程 -6 重复Repeat

using System;

using System.Text;

using System.IO;

using NPOI.HSSF.UserModel;

using NPOI.HPSF;

using NPOI.POIFS.FileSystem;

using NPOI.SS.UserModel;

 

namespace RepeatingRowsAndColumns

{

    class Program

    {

        static void Main(string[] args)

        {

            InitializeWorkbook();

 

            Sheet sheet1 = hssfworkbook.CreateSheet("first sheet");

            hssfworkbook.CreateSheet("second sheet");

            hssfworkbook.CreateSheet("third sheet");

 

            Font boldFont = hssfworkbook.CreateFont();

            boldFont.FontHeightInPoints = 22;

            boldFont.Boldweight = (short)FontBoldWeight.BOLD;

 

            CellStyle boldStyle = hssfworkbook.CreateCellStyle();

            boldStyle.SetFont(boldFont);

 

            Row row = sheet1.CreateRow(1);

            Cell cell = row.CreateCell(0);

            cell.SetCellValue("This quick brown fox");

            cell.CellStyle = (boldStyle);

 

            // Set the columns to repeat from column 0 to 2 on the first sheet

            hssfworkbook.SetRepeatingRowsAndColumns(0, 0, 2, -1, -1);

            // Set the rows to repeat from row 0 to 2 on the second sheet.

            hssfworkbook.SetRepeatingRowsAndColumns(1, -1, -1, 0, 2);

            // Set the the repeating rows and columns on the third sheet.

            hssfworkbook.SetRepeatingRowsAndColumns(2, 4, 5, 1, 2);

 

            WriteToFile();

        }

 

 

        static HSSFWorkbook hssfworkbook;

 

        static void WriteToFile()

        {

            //Write the stream data of workbook to the root directory

            FileStream file = new FileStream(@"test.xls", FileMode.Create);

            hssfworkbook.Write(file);

            file.Close();

        }

 

        static void InitializeWorkbook()

        {

            hssfworkbook = new HSSFWorkbook();

 

            //Create a entry of DocumentSummaryInformation

            DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();

            dsi.Company = "NPOI Team";

            hssfworkbook.DocumentSummaryInformation = dsi;

 

            //Create a entry of SummaryInformation

            SummaryInformation si = PropertySetFactory.CreateSummaryInformation();

            si.Subject = "NPOI SDK Example";

            hssfworkbook.SummaryInformation = si;

        }

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值