using System;
using System.Text;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using NPOI.HSSF.Util;
using NPOI.POIFS.FileSystem;
namespace ChangeSheetTabColorInXls{
class Program
{
static void Main(string[] args)
{
InitializeWorkbook();
HSSFSheet sheet1=hssfworkbook.CreateSheet("Sheet1");
sheet1.TabColorIndex = HSSFColor.RED.index;
HSSFSheet sheet2 = hssfworkbook.CreateSheet("Sheet2");
sheet2.TabColorIndex = HSSFColor.BLUE.index;
HSSFSheet sheet3 = hssfworkbook.CreateSheet("Sheet3");
sheet3.TabColorIndex = HSSFColor.AQUA.index;
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;
}
}
}
|