using System;
using System.Text;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using NPOI.POIFS.FileSystem;
namespace GroupRowAndColumnInXls{
class Program
{
static void Main(string[] args)
{
InitializeWorkbook();
HSSFSheet s = hssfworkbook.CreateSheet("Sheet1");
HSSFRow r1 = s.CreateRow(0);
HSSFRow r2 = s.CreateRow(1);
HSSFRow r3 = s.CreateRow(2);
HSSFRow r4 = s.CreateRow(3);
HSSFRow r5 = s.CreateRow(4);
//group row 2 to row 4
s.GroupRow(1, 3);
//group row 2 to row 3
s.GroupRow(1, 2);
//group column 1-3
s.GroupColumn(1, 3);
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;
}
}
}
|