0
votes

I am developing a report in excel format from my .net web application. I am using Open XML SDK to create the excel spreadsheet. The code is working fine when I run it on Visual Studio. But when I publish the application and host it on the IIS server in my machine, it gives me an error. My code is shown below

public void getPivotTable(System.Data.DataTable dt)
{
string exportFile = Context.Server.MapPath("~/files_all/Export/generated.xlsx");
string templateFile = Context.Server.MapPath("~/files_all/Export/template.xlsx");
File.Copy(templateFile, exportFile, true);
using (SpreadsheetDocument spreadsheet = SpreadsheetDocument.Open(exportFile, true))
{    
WorkbookPart workbook = spreadsheet.WorkbookPart;
WorksheetPart worksheet = workbook.WorksheetParts.Last();
SheetData data = worksheet.Worksheet.GetFirstChild<SheetData>();
}

Webpage error details

Message: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500

Please help me solve the issue.

2

2 Answers

0
votes

Error 500 is a generic catch-all server error that say "hey, something went wrong and I can't fulfill your request." You can examine your server log files to find out the exact cause of the error. This is a server error so it really can't be prevented in your code, but it can be handled.

Taken From http://forums.asp.net/p/1178621/1991359.aspx

0
votes

You can use ClosedXml in Codeplex to create/manipulate Excel files in .Net using Open Xml. It is a wrapper over open xml and offers very simple and intutive api to interact with excel files.