I'm trying to use the following code snippet provided as sample to write data on Excel file.
public ActionResult GenerateXLS(string SaveOption)
{
if (SaveOption == null)
return View();
//New instance of XlsIO is created.[Equivalent to launching Microsoft Excel with no workbooks open].
//The instantiation process consists of two steps.
//Step 1 : Instantiate the spreadsheet creation engine.
ExcelEngine excelEngine = new ExcelEngine();
//Step 2 : Instantiate the excel application object.
IApplication application = excelEngine.Excel;
//A new workbook is created.[Equivalent to creating a new workbook in Microsoft Excel]
//The new workbook will have 12 worksheets
IWorkbook workbook = application.Workbooks.Open(DefaultResolveApplicationDataPath(@"QuotePreview.xls"));
IWorksheet sheet = workbook.Worksheets[1];
sheet.FirstVisibleRow = 3;
IFont font = workbook.CreateFont();
font.Bold = true;
...
try
{
//Saving the workbook to disk.
if (SaveOption == "Xls")
{
//Save as .xls format
return excelEngine.SaveAsActionResult(workbook, "Quote1.xls", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel97);
}
//Save as .xlsx format
else
{
workbook.Version = ExcelVersion.Excel2013;
return excelEngine.SaveAsActionResult(workbook, "Quote1.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2013);
}
}
catch (Exception)
{
}
//Close the workbook.
workbook.Close();
excelEngine.Dispose();
return View();
}
private string DefaultResolveApplicationDataPath(string fileName)
{
//string dataPath = string.Format("{0}\\Common\\Data\\XlsIO\\", Request.PhysicalPath.ToLower().Split(new string[] { "\\XlsIO" }, StringSplitOptions.None));
//return string.Format("{0}\\{1}", dataPath, fileName);
string folderName = "Data\\XlsIO";
string dataPath = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\Common").FullName;
if (folderName != string.Empty)
dataPath += "\\" + folderName;
return string.Format("{0}\\{1}", dataPath, fileName);
}
When I compile, I get the error message Unable to find method SaveAsActionResult for ExcelEngine object.
Must I define an extension as explained in http://help.syncfusion.com/file-formats/xlsio/asp-net-mvc?