Nopiは、式の使用を伴わずに使用されています

// Excelファイルのオブジェクトを作成
HSSFWorkbookワークブック=新しい新しいHSSFWorkbookを();
//シートを追加
ISheetシート= workbook.CreateSheet( "シート1");
sheet.DefaultRowHeight = 300;
//タイトル作成
IRow rowTitle = sheet.CreateRowを(0 );

//设置タイトル的样式
rowTitle.Height = 500;
ICellStyle styleTitle = workbook.CreateCellStyle()。
styleTitle.Alignment = Horizo​​ntalAlignment.Center。
styleTitle.VerticalAlignment = VerticalAlignment.Center。
IFont fontTitle = workbook.CreateFont()。
fontTitle.FontName = "宋体"。
fontTitle.FontHeightInPoints = 18。
styleTitle.SetFont(fontTitle)。
ICELL cellTitle = rowTitle.CreateCell(0)。
cellTitle.SetCellValue( "文件" + stratTime.Substring(0,7))。
cellTitle.CellStyle = styleTitle。
sheet.AddMergedRegion(新しいCellRangeAddress(0、0、0、9))。//合并单元格

//创建表格样式
IFontフォント= workbook.CreateFont()。
font.FontName = "宋体"。
font.FontHeightInPoints = 10。
ICellStyleスタイル= workbook.CreateCellStyle();
style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin。
style.BottomBorderColor = HSSFColor.Black.Index。
style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin。
style.LeftBorderColor = HSSFColor.Black.Index。
style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin。
style.RightBorderColor = HSSFColor.Black.Index。
style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin。
style.TopBorderColor = HSSFColor.Black.Index。
style.Alignment = Horizo​​ntalAlignment.Center。
style.SetFont(フォント)。

//这是动销记录为0的样式
ICellStyle STYLE1 = workbook.CreateCellStyle()。
style1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin。
style1.BottomBorderColor = HSSFColor.Black.Index。
style1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin。
style1.LeftBorderColor = HSSFColor.Black.Index。
style1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin。
style1.RightBorderColor = HSSFColor.Black.Index。
style1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin。
style1.TopBorderColor = HSSFColor.Black.Index。
style1.Alignment = Horizo​​ntalAlignment.Center。
style1.VerticalAlignment = VerticalAlignment.Center。
style1.SetFont(フォント)。
style1.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index。
style1.FillPattern = FillPattern.SolidForeground。

//会社とブランドスタイルのピンは0ではありません
ICellStyleスタイル2 workbook.CreateCellStyle =();
style2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
style2.BottomBorderColor = HSSFColor.Black.Index;
style2.BorderLeft = NPOI。 SS.UserModel.BorderStyle.Thin;
style2.LeftBorderColor = HSSFColor.Black.Index;
style2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
style2.RightBorderColor = HSSFColor.Black.Index;
style2.BorderTop = NPOI.SS. UserModel.BorderStyle.Thin;
style2.TopBorderColor = HSSFColor.Black.Index;
style2.Alignment = Horizo​​ntalAlignment.Left;
style2.VerticalAlignment = VerticalAlignment.Center;
style2.SetFont(フォント);
//同社ブランドのスタイルピンと0として記録
ICellStyle style3 = workbook.CreateCellStyle()。
style3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin。
style3.BottomBorderColor = HSSFColor.Black.Index。
style3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin。
style3.LeftBorderColor = HSSFColor.Black.Index。
style3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin。
style3.RightBorderColor = HSSFColor.Black.Index。
style3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin。
style3.TopBorderColor = HSSFColor.Black.Index。
style3.Alignment = Horizo​​ntalAlignment.Left。
style3.VerticalAlignment = VerticalAlignment.Center。
style3.SetFont(フォント)。
style3.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index。
style3.FillPattern = FillPattern.SolidForeground。

//ヘッダの作成
(1)IRow rowHead = sheet.CreateRowと、
rowHead.CreateCell(0).SetCellValue( "ストリート");
rowHead.GetCell(0)= .CellStyleスタイル; //指定されたスタイル
sheet.SetColumnWidth(0、 256 * 25)。

rowHead.CreateCell(1).SetCellValue( "公司")。
rowHead.GetCell(1).CellStyle =スタイル。
sheet.SetColumnWidth(1、256 * 30)。

rowHead.CreateCell(2).SetCellValue( "品牌")。
rowHead.GetCell(2).CellStyle =スタイル。
sheet.SetColumnWidth(2、256 * 30)。

rowHead.CreateCell(3).SetCellValue( "ピン先月の時間");
(3)rowHead.GetCellスタイル= .CellStyle;
sheet.SetColumnWidth(3、* 15 256。);

rowHead.CreateCell(4).SetCellValue( "ベンダーの数");
rowHead.GetCell = .CellStyleスタイル(4);
sheet.SetColumnWidth(4、256 * 15);
(5)rowHead.CreateCell .SetCellValue(「トータル・製品量");
rowHead.GetCell(5)= .CellStyleスタイル;
sheet.SetColumnWidth(5、* 15 256);
rowHead.CreateCell(6).SetCellValue("月ストレージ量「);
rowHead.GetCell(6)。スタイル= .CellStyle;
sheet.SetColumnWidth(6、256 * 15。);
rowHead.CreateCell .SetCellValue( "月の総ライブラリー")(7)、
(7)rowHead.GetCell .CellStyle =スタイル;
sheet.SetColumnWidth(7。 * 15、256);
rowHead.CreateCell(8).SetCellValue( "月のピンレコード");。
。rowHead.GetCell(8).CellStyle =スタイル;
sheet.SetColumnWidth(8、256 * 15);。
。rowHead.CreateCell(9) 。SetCellValue(「かエントリゼロ」)。
rowHead.GetCell(9).CellStyle =スタイル。
sheet.SetColumnWidth(* 15 9、256)。

int型rowIndexに= 2;
foreachの(クエリ内のvarアイテム)
{
IRow rowContent = sheet.CreateRow(rowIndexプロパティ); //创建新行
であれば(item.CountDX == 0)
{
rowContent.CreateCell(0).SetCellValue(item.Street.ToString()) ;
rowContent.GetCell(0).CellStyle = STYLE1。
rowContent.CreateCell(1).SetCellValue(Convert.ToString(item.Compnay))。
rowContent.GetCell(1).CellStyle = style3。
rowContent.CreateCell(2).SetCellValue(Convert.ToString(item.Brand))。
rowContent.GetCell(2).CellStyle = style3。
rowContent.CreateCell(3).SetCellValue(Convert.ToString(item.DateDX))。
rowContent.GetCell(3).CellStyle = STYLE1。
rowContent.CreateCell(4).SetCellValue(Convert.ToString(item.Supplier))。
rowContent.GetCell(4).CellStyle = STYLE1。
rowContent.CreateCell(5).SetCellValue(Convert.ToString(item.ProductCount))。
rowContent.GetCell(5).CellStyle = STYLE1。
rowContent.CreateCell(6).SetCellValue(Convert.ToString(item.WarehousingCount))。
rowContent.GetCell(6).CellStyle = STYLE1。
rowContent.CreateCell(7).SetCellValue(Convert.ToString(item.checkout))。
rowContent.GetCell(7).CellStyle = STYLE1。
rowContent.CreateCell(8).SetCellValue(Convert.ToString(item.CountDX))。
rowContent.GetCell(8).CellStyle = STYLE1。
rowContent.CreateCell(9).SetCellValue(Convert.ToString(item.Reading))。
rowContent.GetCell(9).CellStyle = STYLE1。
}

{
rowContent.CreateCell(0).SetCellValue(item.Street.ToString())。
rowContent.GetCell(0).CellStyle =スタイル。
rowContent.CreateCell(1).SetCellValue(Convert.ToString(item.Compnay))。
rowContent.GetCell(0).CellStyle =スタイル2。
rowContent.CreateCell(2).SetCellValue(Convert.ToString(item.Brand))。
rowContent.GetCell(0).CellStyle =スタイル2。
rowContent.CreateCell(3).SetCellValue(Convert.ToString(item.DateDX))。
rowContent.GetCell(3).CellStyle =スタイル。
rowContent.CreateCell(4).SetCellValue(Convert.ToString(item.Supplier))。
rowContent.GetCell(4).CellStyle =スタイル。
rowContent.CreateCell(5).SetCellValue(Convert.ToString(item.ProductCount))。
rowContent.GetCell(5).CellStyle =スタイル。
rowContent.CreateCell(6).SetCellValue(Convert.ToString(item.WarehousingCount))。
rowContent.GetCell(6).CellStyle =スタイル。
rowContent.CreateCell(7).SetCellValue(Convert.ToString(item.checkout))。
rowContent.GetCell(7).CellStyle =スタイル。
rowContent.CreateCell(8).SetCellValue(Convert.ToString(item.CountDX))。
rowContent.GetCell(8).CellStyle =スタイル。
rowContent.CreateCell(9).SetCellValue(Convert.ToString(item.Reading))。
rowContent.GetCell(9).CellStyle =スタイル。
}
++ rowIndexに。
}
IRow rowContent2 = sheet.CreateRow(rowIndexプロパティ+ 2); //创建新行
rowContent2.CreateCell(0).SetCellValue( "代表动销记录为0")。
rowContent2.CreateCell(1).SetCellValue( "")。
rowContent2.CreateCell(2).SetCellValue( "制表日期" + System.DateTime.Now.ToString( "YYYYMMDD"))。
rowContent2.CreateCell(3).SetCellValue( "")。

sheet.AddMergedRegion(新しいCellRangeAddress(rowIndexに+ 2、rowIndexに+ 2、2、3))。//合并单元格
rowContent2.GetCell(0).CellStyle = STYLE1。
rowContent2.GetCell(2).CellStyle = STYLE1。
rowContent2.GetCell(3).CellStyle = STYLE1。

//セルスタイルマージ
; ICellStyle workbook.CreateCellStyle CellStyle =()
cellstyle.VerticalAlignment = VerticalAlignment.Center;
cellstyle.Alignment = Horizo​​ntalAlignment.Center;
//マージ行
INTカウント= query.Count()+ 2 ; // 合計ユニット行数
のためには、(INT I = 0;私は数<; Iは++)
{
//現在の行0得る
文字列値= sheet.GetRow(I).GetCell (0).StringCellValue。

終了=私はint型、
終了日を見つける//
ために(int型I = J + 1; J <COUNT; Jを++)
{
// 0の次の行を取得
文字列値1を= sheet.GetRow(J).GetCell (0)。 StringCellValue;
IF(!値= VALUE1)
{
エンド= J - 1;
BREAK;
}
そうIF(値== J == query.Count VALUE1 ||())
{
エンド= J。

}
}

sheet.AddMergedRegion(新しいCellRangeAddress(I、終わり 、0、0)); // そして細胞および
VAR = sheet.GetRowセル(I).GetCell(0);
cell.CellStyle = CellStyle;
I = END;
}
/ /クライアントへの書き込み
System.IO.MemoryStream新しい新しいSystem.IO.MemoryStream MS =();
workbook.Write(MS);
ms.Seek(0、SeekOrigin.Begin)。

おすすめ

転載: www.cnblogs.com/geekX/p/11445427.html