TheOne

TheOne

  • NA
  • 3
  • 20.7k

Column Width Excel file

Mar 6 2012 4:55 AM
Hi,
 
I created an Excel file from a datatable but i have a problem to resize column, this is the first problem. The second is how can i write in a specific cell(for example the cell(1,2) I need this for the header for example).Can you help me?.This is my code

  DataTable dt = (DataTable) ViewState["CurrentTable"];
 
  Workbook book = new Workbook();
  WorksheetStyle style = book.Styles.Add("Entete");
  style.Font.Bold = true;
  style.Font.Color = "White";
  style.Alignment.Horizontal = StyleHorizontalAlignment.Center;
  style.Interior.Color = "Blue";
  style.Interior.Pattern = StyleInteriorPattern.Solid;
 
  //create the first sheet
  Worksheet sheet = book.Worksheets.Add("Detail Seance");
 
  //The second sheet
  Worksheet sheetConf = book.Worksheets.Add("Total");
 
 
  //The header
  WorksheetRow row = sheet.Table.Rows.Add();
  row.Cells.Add(new WorksheetCell("Historique Exo"){ MergeAcross = 5 });
 
  row = sheet.Table.Rows.Add();
  Excel.Range range;
 
  foreach (DataColumn dc in dt.Columns)
  {
  row.Cells.Add(new WorksheetCell(dc.ColumnName, DataType.String, "Entete"));
  }
 
  int j;
  foreach (DataRow dr in dt.Rows)
  {
  row = sheet.Table.Rows.Add();
  for (j = 0; j < dt.Columns.Count; j++)
  {
  row.Cells.Add(new WorksheetCell(dr[j].ToString()));
  //I want for example to specify the width of the cell added
  }
  }
 
  //save Excel file
  book.Save(Response.OutputStream);


I hope that you can help

tahnks

Answers (2)