Link to home
Start Free TrialLog in
Avatar of Mani Pazhana
Mani PazhanaFlag for United States of America

asked on

Export to excel from Console app

Hello Experts,
I need to export string data to excel using console app (C#) without using any third party libraries...

i am getting object reference error...HttpContext.Current.Response.ClearContent();


here is my code so far...( i have it on class library project)

using System.Web;

 private void ExportToExcel(string strData)
        {
            try
            {
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=BatchResponse.xls");
            HttpContext.Current.Response.ContentType = "application/excel";
            HttpContext.Current.Response.Write(strData);
            HttpContext.Current.Response.End();
            }
            catch (Exception ex)
            {
                log.LogExceptionError("Batch Settlement Process - ExportToExcel", ex);
            }
            finally
            {
                log = null;
            }
        }
           

Any help?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mani Pazhana

ASKER

Thanks. figured out the solution using StreamWriter.