Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am using this code in controller for export to excel. I am using NPOI dll for Export to excel.</p> <blockquote> <p>public ActionResult ExportToExcelCombine(string select_rows) {</p> <p>var workbook = new HSSFWorkbook();</p> <pre><code> string[] test = select_rows.ToString().Split(';'); var sheet = workbook.CreateSheet("Summary"); int row_index = 0; var excelnewrow = sheet.CreateRow(row_index); excelnewrow.CreateCell(0).SetCellValue("Entity Name"); row_index++; excelnewrow = sheet.CreateRow(row_index); excelnewrow.CreateCell(0).SetCellValue("Type of Entity"); row_index++; excelnewrow = sheet.CreateRow(row_index); excelnewrow.CreateCell(0).SetCellValue("Industry"); row_index++; excelnewrow = sheet.CreateRow(row_index); excelnewrow.CreateCell(0).SetCellValue("Country"); row_index++; excelnewrow = sheet.CreateRow(row_index); excelnewrow.CreateCell(0).SetCellValue(""); row_index++; excelnewrow = sheet.CreateRow(row_index); HSSFCellStyle style_summary_color = workbook.CreateCellStyle(); // cell background style_summary_color.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.BLACK.index; style_summary_color.FillPattern = HSSFCellStyle.SOLID_FOREGROUND; // font color HSSFFont font_summary_color = workbook.CreateFont(); font_summary_color.Color = NPOI.HSSF.Util.HSSFColor.WHITE.index; style_summary_color.SetFont(font_summary_color); excelnewrow.RowStyle = style_summary_color; excelnewrow.CreateCell(0).SetCellValue("Facebook"); excelnewrow.GetCell(0).CellStyle = style_summary_color; row_index++; excelnewrow = sheet.CreateRow(row_index); excelnewrow.CreateCell(0).SetCellValue(""); </code></pre> <p>using (var exportData = new MemoryStream()) { workbook.Write(exportData);</p> <pre><code> string saveAsFileName = string.Format("Report-{0:d}.xls", DateTime.Now).Replace("/", "-"); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName)); Response.Clear(); Response.BinaryWrite(exportData.GetBuffer()); Response.End(); return File(saveAsFileName, "application/vnd.ms-excel", saveAsFileName); } </code></pre> <p>TempData["Message"] = "Excel report created successfully!";</p> <pre><code> //return File(buffer, "application/vnd.ms-excel"); return RedirectToAction("ExcelPackage"); </code></pre> <p>}</p> </blockquote> <p>In view, i am using</p> <blockquote> <p> </p> </blockquote> <p>In jquery, i am using</p> <blockquote> <p>$(document).ready(function () { $("#export_excel ").click(function (event) { // $(this).attr('href', "/Home/ExportToExcelCombine?select_rows="+ $('#select_rows').val()); var val=$('#select_rows').val(); $(this).attr('href', '@Url.Action("ExportToExcelCombine", "Home")?select_rows='+val); }); });</p> </blockquote> <p>I am using $('#select_rows').val() for hidden field value, which changes when i select some rows in the Jtable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload