Solved

Export to excel from Console app

Posted on 2013-06-04
2
1,024 Views
Last Modified: 2013-06-05
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
0
Comment
Question by:mani_sai
2 Comments
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
Comment Utility
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
 
LVL 8

Author Closing Comment

by:mani_sai
Comment Utility
Thanks. figured out the solution using StreamWriter.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now