How to open a text file and convert it to excel at the same time ,..

There are lots of ways of doing this ,.. but this is perhaps the eaciest (c:

public static void Write()
{

HttpResponse response =HttpContext.Current.Response;

// make sure nothing is in response stream
response.Clear();
response.Charset =
"";

// set MIME type to be Excel file.
response.ContentType ="application/vnd.ms-excel";
response.AddHeader(
"Content-Disposition", "attachment; filename=\"MyExcel_" + DateTime.Now.ToString() + "\".xls");

// Send the data. Tab delimited, with newlines.
System.IO.StreamReader reader = new System.IO.StreamReader(HttpContext.Current.Request.MapPath("~/Mytext.txt"));

response.Write(reader.ReadToEnd());
reader.Close();

// Close response stream.
response.End();

}

prettey cool if i may say so ,.. (c:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: