locked
excel 2007 column autofit width how? RRS feed

  • Question

  • User-271551006 posted

    below is my code

     public static void ExportToExcel(IEnumerable<dynamic> data, string sheetName)
            {
                XLWorkbook wb = new XLWorkbook();
                var ws = wb.Worksheets.Add(sheetName);
                ws.Cell(2, 1).InsertTable(data);
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                HttpContext.Current.Response.AddHeader("content-disposition", String.Format(@"attachment;filename={0}.xlsx", sheetName.Replace(" ", "_")));

                using (MemoryStream memoryStream = new MemoryStream())
                {
                    wb.SaveAs(memoryStream);
                    memoryStream.WriteTo(HttpContext.Current.Response.OutputStream);
                    memoryStream.Close();
                }

                HttpContext.Current.Response.End();
            }

    my problem is in excel column of type column if not autofit there is ######

    how do i make all columns autofit width or only particular column of type date autofit width?

    Wednesday, September 2, 2015 5:59 AM

Answers

All replies