public static byte[] ExportToBuffer(IWorkbook workbook, params SheetFormatterContainer[] containers) { foreach (var container in containers) { var sheet = workbook.GetSheet(container.SheetName); var context = new SheetFormatterContext(sheet, container.Formatters); context.Format(); } return workbook.SaveToBuffer(); }
/// 导出格式化处理后的文件到二进制文件流 /// <param name="templateFile"></param> /// <param name="containers"></param> /// <returns></returns> public static byte[] ExportToBuffer(string templateFile, params SheetFormatterContainer[] containers) { var workbook = NPOIHelper.LoadWorkbook(templateFile); foreach (var container in containers) { var sheet = workbook.GetSheet(container.SheetName); var context = new SheetFormatterContext(sheet, container.Formatters); context.Format(); } return workbook.SaveToBuffer(); }
/// 导出格式化处理后的文件到二进制文件流 /// <param name="templateFile"></param> /// <param name="containers"></param> /// <returns></returns> public static byte[] ExportToBuffer(string templateFile, params SheetFormatterContainer[] containers) { var workbook = NPOIHelper.LoadWorkbook(templateFile); foreach (var container in containers) { var sheet = workbook.GetSheet(container.SheetName); var context = new SheetFormatterContext(sheet, container.Formatters); context.Format(); } return(workbook.SaveToBuffer()); }
/// 格式化操作 /// <param name="context"></param> public override void Format(SheetFormatterContext context) { var rowIndex = context.GetCurrentRowIndex(CellPoint.X); var row = context.Sheet.GetRow(rowIndex); if (null == row) { row = context.Sheet.CreateRow(rowIndex); } var cell = row.GetCell(CellPoint.Y); if (null == cell) { cell = row.CreateCell(CellPoint.Y); } SetCellValue(cell, Value); }
/// 格式化操作 /// <param name="context"></param> public override void Format(SheetFormatterContext context) { var rowIndex = context.GetCurrentRowIndex(CellPoint.X); var row = context.Sheet.GetRow(rowIndex); if (null == row) { row = context.Sheet.CreateRow(rowIndex); } var cell = row.GetCell(CellPoint.Y); if (null == cell) { cell = row.CreateCell(CellPoint.Y); } if (cell.CellType.Equals(CellType.String)) { SetCellValue(cell, cell.StringCellValue.Replace(string.Format("$[{0}]", ParameterName), Value)); } }
/// 格式化操作 /// <param name="context"></param> public abstract void Format(SheetFormatterContext context);