public void createWorkBook(string path, string date, List <DataHolder> dict) { ConsolUtil.GetDate(date); _wb = new XSSFWorkbook(); _sheet = _wb.CreateSheet(DateStorage.PartialDate); workbookData(dict); if (File.Exists(path)) { File.Delete(path); } using (FileStream fs = File.Create(path)) { _wb.Write(fs); _wb.Close(); } }
private static void workbookData(List <DataHolder> dict) { _numOfFarms = ConsolUtil.getNumberofFarms(); for (int row = 0; row < _rowLabels.Count; row++) { rowLabeler(row, dict); } int col = 1; foreach (DataHolder b in dict) { ICell cell; string stripper = b.Data_array.Substring(1, b.Data_array.Length - 2); string[] sArray = stripper.Split(','); { XSSFCellStyle style = (XSSFCellStyle)_wb.CreateCellStyle(); XSSFFont font = (XSSFFont)_wb.CreateFont(); font.FontName = "Arial"; cell = _sheet.GetRow(0).CreateCell(col); style.SetFillForegroundColor(new XSSFColor(Color.FromArgb(255, 242, 204))); style.FillPattern = FillPattern.SolidForeground; style.Alignment = HorizontalAlignment.Left; try { cell.SetCellValue(ConsolUtil.GetFarmName(b.Branch_id)); } catch { cell.SetCellValue("N/A"); } font.FontHeightInPoints = 14; style.SetFont(font); cell.CellStyle = style; } for (int i = 0; i < sArray.Length; i++) { XSSFCellStyle style = (XSSFCellStyle)_wb.CreateCellStyle(); XSSFFont font = (XSSFFont)_wb.CreateFont(); cell = _sheet.GetRow(_dataCells[i]).CreateCell(col); style.Alignment = HorizontalAlignment.Left; ConsolUtil.InputDataToSheet(sArray[i], cell); font.FontHeightInPoints = 11; style.SetFont(font); cell.CellStyle = style; } col++; } _sheet.AutoSizeColumn(1); _sheet.AutoSizeColumn(2); _sheet.AutoSizeColumn(1); }