NPOI 1.2.3教程 -6 重复Repeat

来源:互联网 发布:备份数据库管家婆 编辑:程序博客网 时间:2024/05/20 04:49

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;

        }

    }

}

原创粉丝点击