Regrading Excel Generation.
-
When i generate excel in asp.net it will generate but when i open & then saved this excel it showed "save as type" "web page".
-
When i generate excel in asp.net it will generate but when i open & then saved this excel it showed "save as type" "web page".
harish mehra wrote:
when i open & then saved this excel it showed "save as type" "web page
Yes. That's how web works. What is your question?
Navaneeth How to use google | Ask smart questions
-
When i generate excel in asp.net it will generate but when i open & then saved this excel it showed "save as type" "web page".
Hard to know exactly what you're doing from this gibberish ( it's not even a question ), but, I suspect you're failing to set the MIME type when you write your file down to the client.
Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
-
When i generate excel in asp.net it will generate but when i open & then saved this excel it showed "save as type" "web page".
Try this example. I did this in one of my project. I generated the excel after reading the values from a GridView. STEP 1:Create a function call DownLoad() to download the excel file
/* Function Name: Download()
Purpose: Downloads the Excel file*/** private void Download()**
{
/* Set necessary properties to for the response object to render excel document.*/Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.ContentType = "application/vnd.xls"; Response.Charset = ""; this.EnableViewState = false; /\* Creating a string writer object \*/ System.IO.StringWriter objStringWriter = **_GenerateExcelBody()_**; /\* Content written to the HtmlTextWriter (StringWriter) is written to the Response object.\*/ Response.Write(objStringWriter.ToString()); Response.End(); }
STEP 2:Create a function called GenerateExcelBody() to generate the excel boby
/* Function Name: GenerateExcelBody()
Purpose: Creates the Excel body */**private System.IO.StringWriter _GenerateExcelBody()_** { /\* Instantiate a HtmlTextWriter with a System.IO.StringWriter object \*/ System.IO.StringWriter objStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter objHtmlTextWriter = new System.Web.UI.HtmlTextWriter(objStringWriter); string strVal =string.Empty; /\* Page wise Looping thru the grid \*/ for (int i = 0; i < grEims.Rows.Count; i++) { if (i % 2 == 0) { strVal += "<tr bgcolor='white'><td>" + grEims.Rows\[i\].Cells\[0\].Text + " " + grEims.Rows\[i\].Cells\[1\].Text + " " + grEims.Rows\[i\].Cells\[2\].Text.ToString() + " " + grEims.Rows\[i\].Cells\[3\].Text.ToString() + " " + grEims.Rows\[i\].Cells\[4\].Text.ToString() + " " + grEims.Rows\[i\].Cells\[5\].Text.ToString() + "</td
-
Try this example. I did this in one of my project. I generated the excel after reading the values from a GridView. STEP 1:Create a function call DownLoad() to download the excel file
/* Function Name: Download()
Purpose: Downloads the Excel file*/** private void Download()**
{
/* Set necessary properties to for the response object to render excel document.*/Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.ContentType = "application/vnd.xls"; Response.Charset = ""; this.EnableViewState = false; /\* Creating a string writer object \*/ System.IO.StringWriter objStringWriter = **_GenerateExcelBody()_**; /\* Content written to the HtmlTextWriter (StringWriter) is written to the Response object.\*/ Response.Write(objStringWriter.ToString()); Response.End(); }
STEP 2:Create a function called GenerateExcelBody() to generate the excel boby
/* Function Name: GenerateExcelBody()
Purpose: Creates the Excel body */**private System.IO.StringWriter _GenerateExcelBody()_** { /\* Instantiate a HtmlTextWriter with a System.IO.StringWriter object \*/ System.IO.StringWriter objStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter objHtmlTextWriter = new System.Web.UI.HtmlTextWriter(objStringWriter); string strVal =string.Empty; /\* Page wise Looping thru the grid \*/ for (int i = 0; i < grEims.Rows.Count; i++) { if (i % 2 == 0) { strVal += "<tr bgcolor='white'><td>" + grEims.Rows\[i\].Cells\[0\].Text + " " + grEims.Rows\[i\].Cells\[1\].Text + " " + grEims.Rows\[i\].Cells\[2\].Text.ToString() + " " + grEims.Rows\[i\].Cells\[3\].Text.ToString() + " " + grEims.Rows\[i\].Cells\[4\].Text.ToString() + " " + grEims.Rows\[i\].Cells\[5\].Text.ToString() + "</td
It is useful for generating excel but u can see when we open that excel and than save this excel it displayed save as type web page. can it display default save type as microsoft Excel?