using NPOI;
using NPOI.HSSF;
using NPOI.HSSF.UserModel;
using NPOI.POIFS;
using NPOI.Util;
//宣告Excel
HSSFWorkbook workbook = new HSSFWorkbook();
MemoryStream ms = new MemoryStream();
HSSFSheet Sheet= (HSSFSheet)workbook.CreateSheet(SheetName);
//釋放workbook
workbook.Write(Oldms);
workbook= null;ms.Close(); ms.Dispose();
//合併儲存格
sheet.AddMergedRegion(new NPOI.SS.Util.Region(Col, Row, Cols, Rows));
//設定儲存格格式
HSSFCellStyle Style = (HSSFCellStyle)workbook.CreateCellStyle();
Style.WrapText = true;//自動換行
Style.BorderTop = NPOI.SS.UserModel.CellBorderType.THIN;//框線
Style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;//文字置中
Style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.LEFT;//靠左對齊
//設定文字格式
HSSFFont font = null;
font = (HSSFFont)workbook.CreateFont();
font.FontHeightInPoints = 12;//字型大小
Font12LeftStyle.SetFont(font);
//指定直式或橫式 true=橫式 false=直式
sheet.PrintSetup.Landscape = true;
//指定紙張大小 A3=8, A4=9, Letter=1
sheet.PrintSetup.PaperSize = 9;
//設定邊距置中
sheet.HorizontallyCenter = true;
//sheet.VerticallyCenter = true;
//設定一頁寬一頁高
sheet.Autobreaks = true;
sheet.PrintSetup.FitHeight = (short)1;
sheet.PrintSetup.FitWidth = (short)1;
留言列表