NPOI匯出EXCEL 列印設定分頁及列印標題
在用NPOI匯出EXCEL的時候設定分頁,在網上有查到用sheet1.SetRowBreak(i)方法,但一直都沒有起到作用。經過研究是要設定 sheet1.FitToPage = false; 而這個屬性預設是true的,怪不得一直設定都不起作用。
設定列印標題用
hssfworkbook.SetRepeatingRowsAndColumns(0, 0, 5, 0, 5);
但最新版本已經有新的方法了。
sheet.RepeatingRows=new CellRangeAddress(0,5,0,5)
Sheet sheet1 = hssfworkbook.CreateSheet("Sheet1");
sheet1.SetMargin(MarginType.RightMargin, (double)0.5);
sheet1.SetMargin(MarginType.TopMargin, (double)0.6);
sheet1.SetMargin(MarginType.LeftMargin, (double)0.4);
sheet1.SetMargin(MarginType.BottomMargin, (double)0.3);
sheet1.PrintSetup.Copies = 3; sheet1.PrintSetup.NoColor = true;
sheet1.PrintSetup.Landscape = true;
sheet1.PrintSetup.PaperSize = (short)PaperSize.A4;
sheet1.PrintSetup.FitHeight = 2;
sheet1.PrintSetup.FitWidth = 3;
sheet1.IsPrintGridlines = true;
//是否自適應介面 sheet1.FitToPage = false;
//設定列印標題 hssfworkbook.SetRepeatingRowsAndColumns(0, 0, 5, 0, 5);