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
LVL 8
mani_saiAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Julian HansenConnect With a Mentor Commented:
Where is  HttpContext defined ?

As a matter of interest, if this is a console app why are you using Http to export to Excel ?
0
 
mani_saiAuthor Commented:
Thanks. figured out the solution using StreamWriter.
0
All Courses

From novice to tech pro — start learning today.