- Home
- Forum
- ASP.NET MVC
- Unrecognized SaveAsActionResult method.
Unrecognized SaveAsActionResult method.
Hi,
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?
Can you help me?
Thanks
SIGN IN To post a reply.
1 Reply
SS
Sridhar Sukumar
Syncfusion Team
July 20, 2016 08:56 AM UTC
Hi Claudio,
Thank you for contacting Syncfusion support.
|
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? |
Yes, you need to define an extension.
We have prepared a simple sample for using XlsIO in ASP.NET MVC application which can be downloaded from the following link
Sample link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/Example-813763155.zip
Alternative way:
If you install Nuget package for ASP.NET MVC, then you no need to define the extension for those methods. The Nuget package for ASP.NET MVC can be downloaded from the following link:
Download link:
|
Regards,
Sridhar S
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
CR CLAUDIO RICCARDI
- Jul 19, 2016 08:56 AM UTC
- Jul 20, 2016 08:56 AM UTC