최흥배 | Facebook 님의 자료를 공유합니다.
6개의 좋아요
추가로 ExcelMapper도 남겨놓습니다.
NPOI를 기능을 추가한 것인데 매핑기능이 편한것 같습니다.
단점은 메모리 사용량이 많은 것 같습니다.
리포팅툴을 대신할 수있는 ClosedXML.Report는 한번 사용해봐야겠네요.
Gembox도 좋은 것 같습니다.
https://github.com/mganss/ExcelMapper
public void CreateExcel()
{
var excelMapper = new ExcelMapper();
var columnInfo = excelMapper.AddMapping<ProductModel>("상품명", p => p.상품명);
var setter = columnInfo.SetCell;
columnInfo.SetCellUsing((ICell c, string s) =>
{
setter(c, s);
if (s.Contains("l"))
{
//Something
}
CellUtil.SetCellStyleProperty(c, CellUtil.FILL_FOREGROUND_COLOR, IndexedColors.Red.Index);
CellUtil.SetCellStyleProperty(c, CellUtil.FILL_PATTERN, FillPattern.SolidForeground);
});
excelMapper.Saving += (s, e) =>
{
//칼럼 오토사이즈
//var cols = e.Sheet.GetRow(excelMapper.HeaderRowNumber).LastCellNum;
//for (int i = 0; i < cols; i++)
// e.Sheet.AutoSizeColumn(i);
CellUtil.SetCellStyleProperty(e.Sheet.GetRow(excelMapper.HeaderRowNumber).Cells[0], CellUtil.FILL_FOREGROUND_COLOR, IndexedColors.Red.Index);
CellUtil.SetCellStyleProperty(e.Sheet.GetRow(excelMapper.HeaderRowNumber).Cells[0], CellUtil.FILL_PATTERN, FillPattern.SolidForeground);
};
excelMapper.Save(FileFullPath, Products, SheetName);
}
3개의 좋아요