private static void ApplyColumnsAutoWidth(ExcelWorksheet ws) { int columnCount = ws.CalculateMaxUsedColumns(); for (int i = 0; i < columnCount; i++) ws.Columns[i].AutoFit(); }
public void FormatGradeConversion(ExcelWorksheet ws) { foreach (DataColumn dc in _conversionDataTable.Columns) { if (dc.ColumnName != "PerformanceLevel" && dc.ColumnName != "Color") { ws.Cells[0, dc.Ordinal].Value = dc.ColumnName; ws.Cells[0, dc.Ordinal].Style.Font.Weight = ExcelFont.BoldWeight; } } int rowCount = 1; foreach (DataRow dr in _conversionDataTable.Rows) { ws.Cells[rowCount, 0].Value = dr["Student_ID"].ToString(); ws.Cells[rowCount, 1].Value = dr["Student_Name"].ToString(); ws.Cells[rowCount, 2].Value = dr["RawScore"].ToString(); ws.Cells[rowCount, 2].Style.FillPattern.SetSolid(Color.FromName(dr["Color"].ToString())); ws.Cells[rowCount, 3].Value = dr["ScaleScore"].ToString(); ws.Cells[rowCount, 3].Style.FillPattern.SetSolid(Color.FromName(dr["Color"].ToString())); ws.Cells[rowCount, 4].Value = dr["ConvertedScore"].ToString(); ws.Cells[rowCount, 4].Style.FillPattern.SetSolid(Color.FromName(dr["Color"].ToString())); rowCount++; } int columnCount = ws.CalculateMaxUsedColumns(); for (int i = 0; i < columnCount; i++) { ws.Columns[i].AutoFit(1, ws.Rows[0], ws.Rows[ws.Rows.Count - 1]); } }