Export GridView to Excel (xlsx, Excel 2007 Format)

Hi again,

I was looking online for a way to export gridview to excel in Excel 2007 Format (xlsx). I could only find one solution, gridviewtoexcel. Is this the only way to do it?

Thanks
Bullpit


Thanks,
Max
Let Me Google That For You!
0
bullpit
2/18/2008 4:53:27 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

41 Replies
6186 Views

Similar Articles

[PageSpeed] 18



Hey Bullpit,


Please, do the following :



1st in the html side of your page write this ...

<%
@ Page Language="VB" EnableEventValidation ="false"  AutoEventWireup="false" CodeFile="marquee.aspx.vb" Inherits="marquee" %>




2nd this is the vb code

protected void btnSubmit_Click(object sender, ImageClickEventArgs e)

GridView1.DataSource = 'Place your datasource (datatable/dataset)

GridView1.DataBind()

Response.Clear()

Response.Buffer = True

Response.AddHeader("Content-Disposition", "attachment; filename=MyExcelFileName.xls")

'Choose one of these: as the contentType

'Excel 2003 : "application/vnd.ms-excel"

'Excel 2007 : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

 

Response.ContentType = "application/vnd.ms-excel"

Dim writer As New System.IO.StringWriter()

Dim html As New System.Web.UI.HtmlTextWriter(writer)

GridView1.RenderControl(html)

Response.Write(writer)

Response.End()

End Sub

Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub  


and these links show step by step how to do that:

1 -
http://aspalliance.com/771
2 - http://gridviewguy.com/ArticleDetails.aspx?articleID=86
3 - http://www.c-sharpcorner.com/UploadFile/DipalChoksi/exportxl_asp2_dc11032006003657AM/exportxl_asp2_dc.aspx?ArticleID=000c64fb-8a22-414a-8247-984335aaa0eb


Please, let me know if that helped ...


Please, “Mark as Answer” the post that helped you.
-1
XGmarX
2/18/2008 4:57:09 PM

Thanks for your response but I am talking about xlsx format and not xls format.


Thanks,
Max
Let Me Google That For You!
0
bullpit
2/18/2008 5:03:33 PM



Hey Bullpit,

Welcome @ anytime ...


Yup this one export 2007 format ...

just replace the content type with this one

'Excel 2007 : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

Please, re-check the last post ..


Best regards ...



Please, “Mark as Answer” the post that helped you.
-1
XGmarX
2/18/2008 5:07:00 PM

I had already tried that before starting this thread. It didn't work, Excel cannot open the file exported this way saying that its either corrupted or the extension is not correct. Also, If I leave the extension as .xls, excel can open the file but then its not xlsx format, and if I changed the extension to .xlsx, I get the error.


Thanks,
Max
Let Me Google That For You!
0
bullpit
2/18/2008 5:16:36 PM

 

Hey bullpit,

Extension       MIME Type
.xlsx               application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx                application/vnd.openxmlformats-officedocument.spreadsheetml.template
.potx               application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx              application/vnd.openxmlformats-officedocument.presentationml.slideshow
.pptx               application/vnd.openxmlformats-officedocument.presentationml.presentation
.sldx               application/vnd.openxmlformats-officedocument.presentationml.slide
.docx              application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx               application/vnd.openxmlformats-officedocument.wordprocessingml.template
.xlam              application/vnd.ms-excel.addin.macroEnabled.12
.xlsb               application/vnd.ms-excel.sheet.binary.macroEnabled.12

These MIME types were added to IIS7 as noted in KB936496.

BTW, the previous code worked fine with me !!!!!!


Please, “Mark as Answer” the post that helped you.
-1
XGmarX
2/18/2008 5:35:26 PM

XGmarX:
Response.AddHeader("Content-Disposition", "attachment; filename=MyExcelFileName.xls")

Did you try MyExcelFileName.xlsx. ?

This is the error I am getting when trying to open the exported file in excel:

Excel cannot open the file "Report.xlsx" because the file format or extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.


Thanks,
Max
Let Me Google That For You!
0
bullpit
2/18/2008 6:30:25 PM


Edited:


Sorry I'm not sure if I did ...

[ I got this MIME while converting a ms-excel 2007 file to binary, and used it to write it back to ms-excel 2007 format and it worked fine !!! ]


Did you change the content type, instead of :

Response.ContentType = "application/vnd.ms-excel"

put

Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"   

Please, let me know if that helped


Please, “Mark as Answer” the post that helped you.
-1
XGmarX
2/18/2008 6:42:42 PM

I didHuh?.This is my code: 

protected void bttnExportXL_Click(object sender, EventArgs e)
    {
       gridViewMaster.AllowPaging = false;
       gridViewMaster.AllowSorting = false;
        Response.Clear();

        //Response.AddHeader("content-disposition", "attachment;filename=Report_"+ DateTime.Now.ToShortDateString() +".xlsx");
        Response.AddHeader("content-disposition", "attachment;filename=Report.xlsx");
        Response.Charset = "";

        // If you want the option to open the Excel file without saving than
        // comment out the line below
        // Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

        //Response.ContentType = "application/vnd.xls";
        
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

        foreach (GridViewRow r in gridViewMaster.Rows)
        {
            if (r.RowType == DataControlRowType.DataRow)
            {
                for (int columnIndex = 0; columnIndex < r.Cells.Count; columnIndex++)
                {
                    r.Cells[columnIndex].Attributes.Add("class", "text");                    
                }
            }            
        }
        
        gridViewMaster.RenderControl(htmlWrite);
        
        string style = @"&lt;style> .text { mso-number-format:\@; } </style> ";
        Response.Write(style);
      
        Response.Write(stringWrite.ToString());
        Response.End();
        
    }
 
Thanks,
Max
Let Me Google That For You!
0
bullpit
2/18/2008 6:46:36 PM

Hi:

  Excel 2007 cannot recognize the pure html format. You'd better use xls as the extension or render the excel format to client end.

Regards


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
2/20/2008 5:58:31 AM

Allen Chen – MSFT:
Excel 2007 cannot recognize the pure html format. You'd better use xls as the extension or render the excel format to client end.

Oh...so you mean I can't do it? Or is there a workaround?

Thanks,
Bullpit


Thanks,
Max
Let Me Google That For You!
0
bullpit
2/20/2008 1:04:59 PM

Hi:

  A workaround is to create xslx file at server end. Write that file and redirect user to it to force the download dialog popup. Though it's very slow since you've to access hard disk instead of memory.

  To do this you can use excel interop:

http://msdn2.microsoft.com/en-us/library/wss56bz7(vs.80).aspx

http://msdn2.microsoft.com/en-us/library/syyd7czh(VS.80).aspx

  Comparing with this I think you'd opt to use xsl as the extension.

  BTW, to correct my statement in my previous post. What I mean is a file with xslx extension but pure html format cannot be recognized by excel 2007.

Regards


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
2/21/2008 1:46:29 AM

Hello Chen,

   So you mean to say if I use .xsl as the extension I should be able to view the file even if I have office 2007 installed on the client computer?

here is the code that I use for creating the excel file which works fine of Excel 2000 but not on 2007

Response.Clear();

Response.Buffer =
true;

Response.ContentType = "application/vnd.ms-excel";

Response.ContentEncoding = System.Text.Encoding.UTF7;

Response.AddHeader("content-disposition", "attachment; filename=" + "MyFile.xsl");

When I use this code I get the same error message as bullpit gets.

How did the code work for XGmarX when it did not work for me and bullpit?

Bullpit did you find a solution for this problem other than creating a file on the server and redirecting the user to it?

Thanks

0
MJ7633
2/27/2008 7:14:32 PM

MJ7633:
Bullpit did you find a solution for this problem other than creating a file on the server and redirecting the user to it?

Nope, I didn't. Since it was not an immediate requirement for me, I let it go for now. Let's see if we get a solution from someone.

 


Thanks,
Max
Let Me Google That For You!
0
bullpit
2/27/2008 8:04:13 PM

Hey Bullpit,

I think I got 95% of the solution. The 5% I did not get is when Excel opens and pops out the same message saying "The file you are trying to open bla bla bla" and I don't know for now how to get rid of it but on that message when I click yes I see my report or excel file. So try using this code for the header.

 Response.Clear();

Response.AddHeader("content-disposition", "attachment; filename=FileName.xls");

Response.Charset = "";

Response.ContentType = "application/vnd.xls"; // This was where the mistake was in my old code Response.ContentType = "application/vnd.ms-excel";

Hope this works for you too.

MJ

0
MJ7633
2/27/2008 8:44:54 PM

MJ-

You are going back to square 1. Export to xls format was never a problem. We are looking for exporting to xlsx format.


Thanks,
Max
Let Me Google That For You!
0
bullpit
2/27/2008 9:08:21 PM

 I'm trying to export a gridview to excel, I'd rather xls because not everyone has the new verison of office nor the nouse to go and get the document converter from microsoft.

I've used the code for exporting xls, and excel 07 gives that annoying message everytime. This is really bad news, makes the process really un-friendly for users, especially those that get scraed by error messages. Asking users to follow instructions for saying yes, you can open the file to excel, then telling them how to save it as a propper xls (rather than html code, which is what is produced) is really tricky.

Crap this.......... 

0
dhassen
2/28/2008 4:00:02 PM

It sure is...


Thanks,
Max
Let Me Google That For You!
0
bullpit
2/28/2008 4:39:03 PM

Hi

I too face the same problem and resolved too..

Solution: First write Response.Write code and then set other response properties like AddHeader, ContentType etc

 

0
nik1234
3/27/2008 2:50:09 PM

Can you post your code?


Thanks,
Max
Let Me Google That For You!
0
bullpit
3/27/2008 2:51:41 PM

This error occures when trying to open xls file with excel 2007.

Try this:

  1. Open your Registry (Start -> Run -> regedit.exe)
  2. Navigate to HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
  3. Right click in the right window and choose New -> DWORD
  4. Type “ExtensionHardening” as the name (without the quotes)
  5. Verify that the data has the value “0″
0
IMBack
4/4/2008 7:44:06 PM

 

I started with this problem yesterday afternoon and Google led me to this thread.

Has anyone reached a solution?  I looked it my registry, that string wasn't found.

0
MMock
5/2/2008 12:31:05 PM

try this

 

 

protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();

Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

Response.Charset = "";

// If you want the option to open the Excel file without saving than

// comment out the line below

// Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);

GridView1.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

}

public override void VerifyRenderingInServerForm(Control control)
{

// Confirms that an HtmlForm control is rendered for the
//specified ASP.NET server control at run time.

}
 
0
yasserzaid
5/4/2008 2:12:54 AM

yasserzaid:
try this

And what would this do?

 


Thanks,
Max
Let Me Google That For You!
0
bullpit
5/5/2008 11:45:50 AM

I used different code entirely because I realized I needed to open Excel with more than one tab.  Once I did that, the warning prompt was no longer displayed.  Here's my code if you'd like to give it a try:

 

Sub GenerateThreeTabs(ByVal inParam As Integer)

Dim ds As New DataSet

Dim connString As String = _

ConfigurationManager.ConnectionStrings("ConnectToMyDb").ConnectionString

Dim conn As New SqlConnection(connString)Dim command As New SqlCommand()

command.CommandType = CommandType.StoredProcedure

command.Connection = conn

command.CommandText = "up_MyStoredProcedure"

command.Parameters.Add(New SqlParameter("@param", Data.SqlDbType.Int))

command.Parameters("@param").Value = inParam

Dim adapter As New SqlDataAdapter(command)

Try

adapter.Fill(ds)

Catch ex As ExceptionResponse.Write("Submit() Exception " + ex.Message)

conn.Close()

conn.Dispose()

conn = Nothing

Exit Sub

End Try

' Create Excel Application, Workbook, and WorkSheets

Dim xlExcel As New Excel.Application

Dim xlBooks As Excel.Workbooks

Dim xlBook As Excel.Workbook

Dim xlSheets As Excel.Sheets

Dim stdSheet As Excel.Worksheet Dim xlCells As Excel.Range

Dim sFile As String

Dim rescSheet As Excel.Worksheet Dim rescSheet2 As Excel.Worksheet

sFile = Server.MapPath(Request.ApplicationPath) & "\Excel.xls"

xlExcel.Visible = False : xlExcel.DisplayAlerts = False

' Get all workbooks and open first workbook

xlBooks = xlExcel.Workbooks

xlBooks.Open(Server.MapPath(Request.ApplicationPath) &
"\Commissions.xls")

xlBook = xlBooks.Item(1)

' Get all sheets available in first book

xlSheets = xlBook.Worksheets

' Process the summary sheet with results from stored proc's first query - tables(0).

stdSheet = CType(xlSheets.Item(1), Excel.Worksheet)

xlCells = stdSheet.Cells

GenerateSummaryTab(ds.Tables(0), xlCells)

' Get the month details sheet with results from stored proc's second query - tables(1).

rescSheet = CType(xlSheets.Item(2), Excel.Worksheet)

xlCells = rescSheet.Cells

GenerateMonthDetails(ds.Tables(1), xlCells)

' Get the history sheet with results from stored proc's third query - tables(2).

' Also pass in the agent's name from tables(0).

rescSheet2 = CType(xlSheets.Item(3), Excel.Worksheet)

xlCells = rescSheet2.Cells

GenerateMeterSignupHistoryTab(ds.Tables(0).Rows(0).Item(
"Agent").ToString, ds.Tables(2), xlCells) xlExcel.Visible = True

 

End Sub

Private Sub GenerateMonthDetails(ByRef table As DataTable, ByVal xlCells As Excel.Range)

Dim dr As DataRow, ary() As Object

Dim iRow As Integer, iCol As Integer

'Output Column Headers

For iCol = 0 To table.Columns.Count - 1

xlCells(1, iCol + 1) = table.Columns(iCol).ToString

Next

'Output Data

Try

For iRow = 0 To table.Rows.Count - 1

dr = table.Rows.Item(iRow)

ary = dr.ItemArray

For iCol = 0 To UBound(ary)

xlCells(iRow + 2, iCol + 1) = ary(iCol).ToString

Next

Next

Catch ex As Exception

Response.Write(ex.Message)

End Try

End Sub

Private Sub GenerateSummaryTab(ByRef table As DataTable, ByVal xlCells As Excel.Range)

xlCells(1, 2) = table.Rows(0).Item("Agent").ToString

xlCells(5, 2) = table.Rows(0).Item("Commission").ToString

xlCells(5, 3) = table.Rows(0).Item("Usage").ToString

xlCells(5, 4) = table.Rows(0).Item("Storage").ToString xlCells(5, 5) = table.Rows(0).Item("Margin").ToString

End Sub

Private Sub GenerateMeterSignupHistoryTab(ByVal sAgentName As String, ByRef table As DataTable, ByVal xlCells As Excel.Range)

Dim iRow As Integer

xlCells(1, 1) = sAgentName

For iRow = 0 To table.Rows.Count - 1

xlCells(iRow + 2, 2) = table.Rows(iRow).Item("mnth").ToString

xlCells(iRow + 2, 3) = table.Rows(iRow).Item("cnt").ToString

Next

End Sub

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As System.Web.UI.Control)

End Sub

 

HTH and good luck.  What a pain this problem was!

0
MMock
5/5/2008 12:05:17 PM

Thanks for the code. I would assume that this method requires Excel to be installed on server!?


Thanks,
Max
Let Me Google That For You!
0
bullpit
5/5/2008 12:08:52 PM

I'm not 100% sure.  We have Excel on the server and my customers have it too, and I know who my customers are and have control over their software (nice to have things easy,huh?)

 But here's the original link where I got my code, if you want to see its origin.

http://www.c-sharpcorner.com/Blogs/BlogDetail.aspx?BlogId=283

0
MMock
5/5/2008 12:27:21 PM

I am surprised to see that there is no clear solution for this problem so far.

I am facing the same problem. I want to export DataTable to excel 2007 because there is some limitations with Excel 2003 where you can only work on 65,000 records and I am supposed to deal with more than 10,00,000 records at a time which is only possible through Excel 2007.

 
It would be a great help to me if any one can come up with solution.

Thanks !
 


Muhammad Shahanshah Ansari
Software Engineer, Bangalore
0
shahahanshah
8/8/2008 5:26:02 AM

 surely the asp.net team woul'd have known we'll want to export things to excel 2007?

None of the mods or bods at microsoft got an answer to this? 

0
dhassen
8/12/2008 8:11:34 AM

hii

i hv done all code for Export GridView to Excel and its working fine.

but when i m going to open excel file , for some content like this

1)ACCF Procedure – 1 of 4  it display like this  ACCF Procedure – 1 of 4

2)References – 1 of 7 it display like this  References – 1 of 7.

from above i think big dash sign creating problem.but i m not sure. why its display like this –.

please help me for this problem.



 

 



Regards
Jony Shah
0
jsshah
10/23/2008 1:40:30 PM

Hi, I'm rendering data from a DataTable to a temp Excel file on client side, and it's working for Excel 2003 + browers IE7/Firefox 3. I'm supprised to see that the MIME type specified for Response.ContentType does NOT even matter. A blank string will work just fine! I guess the most current browsers know by file extensions to which application they should call when asking for opening a known file type? My code is as below and it works on ASP.NET 2.0 on both WinXP and Win2003 platforms (only tested with Excel 2003 though, have not installed Excel 2007, which is too big for a slow PC):

    protected void btnViewExcel_Click(object sender, EventArgs e)
    {
        DataTable dt = GetTdDataDable(); //build a DataTable with a private method that is not shown here

        if (!Response.IsClientConnected)
        {//if client no longer connected for a length query, end the Response. Might not work for W2k3 & IIS6
            Response.End();
        }

        GetExcelFromDataTable(dt, Resources.Strings.FileResultXls); //defined an Excel temp file name in the Strings file stored in the App_GlobalResources folder
    }

    /// <summary>
    /// Create an Excel file from a DataTable object and send to browser for client to open/download.
    /// </summary>
    /// <param name="dt">The DataTable object that contains the data needs to be converted into an Excel file</param>
    /// <param name="fileName">A name for the Excel file</param>
    private void GetExcelFromDataTable(DataTable dt, string fileName)
    {
        string attachment = "attachment; filename=" + fileName;
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        //application names below for MIME types of different Excel versions don't seem
        //important to the most current browsers. Even an empty string will work.
        //Response.ContentType = "application/vnd.ms-excel"; //Excel 2003
        //Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; //Excel 2007
        Response.ContentType = string.Empty;

        string tab = "";
        foreach (DataColumn dc in dt.Columns)
        {
            Response.Write(tab + dc.ColumnName);
            tab = "\t";
        }
        Response.Write("\n");

        int i;
        foreach (DataRow dr in dt.Rows)
        {
            tab = "";
            for (i = 0; i < dt.Columns.Count; i++)
            {
                Response.Write(tab + dr[i].ToString());
                tab = "\t";
            }
            Response.Write("\n");
        }
        Response.End();
    }
 

Thanks. John

P.S. Forgot to mention, this might be working for Excel 2007, too, since the MIME type string doesn't even matter. I don't have Excel 2007 installed but if anyone is interested to try, please post your result for your test. Thanks a lot.

0
qizhigang
11/14/2008 2:14:22 AM

 I change the content type as per forum but i still get same error.

my code is like this:

Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";       
Response.Charset = "";  

 

string strFile = "Search_Data_" + System.DateTime.Now.Day.ToString() + month + System.DateTime.Now.Year.ToString() + ".xls";

I also tried file name without any extension

string strFile = "Search_Data_" + System.DateTime.Now.Day.ToString() + month + System.DateTime.Now.Year.ToString() ;

 

Error like this :

The file you are trying to open , .xls' is in a different format than specified by the file extension.Verify that the file is not corrupted and is from a trusted source before opening the file.Do you want to open the file now ?

 

Is anyone have solution other than changes in registry file  for this issue ?

 

 

 

 

0
Umesh
12/19/2008 6:41:27 AM

 I change the content type as per forum but i still get same error.

my code is like this:

Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";       
Response.Charset = "";  

 

string strFile = "Search_Data_" + System.DateTime.Now.Day.ToString() + month + System.DateTime.Now.Year.ToString() + ".xls";

I also tried file name without any extension

string strFile = "Search_Data_" + System.DateTime.Now.Day.ToString() + month + System.DateTime.Now.Year.ToString() ;

 

Error like this :

The file you are trying to open , .xls' is in a different format than specified by the file extension.Verify that the file is not corrupted and is from a trusted source before opening the file.Do you want to open the file now ?

 

Is anyone have solution other than changes in registry file  for this issue ?

 

Thanks,

Umesh

umesh.chape@aurovision.com

 

 

 

0
Umesh
12/19/2008 6:43:17 AM

try this .

if youu want to show your grid data in excel file then use below code.

HttpContext.Current.Response.ClearContent();

HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + strHeading + ".xls");

HttpContext.Current.Response.ContentType = "application/excel";

 

Thanks & Regards

Jony shah


Regards
Jony Shah
0
jsshah
12/20/2008 10:20:39 AM

Hi

I have my application running in Windows 2000 and uses Office 2000.

 Below is the code wrriten to export excel file 

Response.ContentType = "application/vnd.ms-excel"

If i try to run the same code in VISTA or XP which uses Office 2007.

I am getting below error.

"The format not supported ... " what it could be the cause and how to resolve this.

Irrespective of Windows 2000 (Office 2000) , VISTA (Office 2007) or XP(Office 2007).

Kindly help in this

Thanks

Mwalter.

 

 

 


Thanks
Mahiban Walter
0
MWalter
12/23/2008 1:43:14 AM

 That message is microsoft warning message.To remove that warning message please do following steps:

 

1) Run -   regedit
2) Navigate path - HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
3) Rightclick --> new>DWORD>
4) add key ExtensionHardening
5) value = 0

 It works for me in Office 2007.

Please try this and let me know Is it helpful to you or not.

 

Thanks,

Umesh

 

 

 

 

 

0
Umesh
12/23/2008 4:43:25 AM

Hey Umesh 

Thanks, I really appreciate it.

Is there any other way that we can fix this by common code change.

Making registry entry in all client machine is not possible.

Kindly advise.

Walter. 

 


Thanks
Mahiban Walter
0
MWalter
12/23/2008 5:00:03 AM

 Hi Walter,

               Please try this.

Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

I found this on fourm but it is not working for me. try at your site becasue this is working for many people as per fourm.If you found any solution please let me know.

 

Regards,

Umesh

0
Umesh
12/23/2008 5:38:26 AM

HI Umesh

My client has Office 2000 in server m/c , and an application pushes all data into EXCEL file.

now if i access (in XP/VISTA which has Office 2007 installed) that aplication to view the EXCEL file  

am facing the problem.

my concern is i need fix this in my client m/c.

Kindly advise.

Mwalter.

 

 


Thanks
Mahiban Walter
0
MWalter
12/25/2008 4:57:34 AM

Hi

 This is vamshi from Hyd facing same problem 

 To save more than 1 lakh records in excel 2007 format , U have got any solutions please can u inform me

 

thanks

0
vamshi455
3/2/2009 11:38:21 AM

Hi Vanshi,

I think  below is the only solution to solve this , because that is warning message by Microsoft.

Run -   regedit
Navigate path - HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
Rightclick --> new>DWORD>
add key ExtensionHardening
value = 0

 

Thanks,

Umesh


0
Umesh
3/2/2009 11:50:49 AM

Hi

I have faced below issues when i migrate my .NET application accessing Office 2003 to Office 2007. 

Refer the link .. under each issue

Issue 1:

Error message:The file you are trying to open, 'name.ext', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?Description:The warning message is a user-notification function that was added to Excel 2007. The warning message can help prevent unexpected problems that might occur because of possible incompatibility between the actual content of the file and the file name extension.

Reason is MS Office 2007 uses XML formatter and MS Office 2000 uses HTML formatter. 

Microsoft link to refer:  http://support.microsoft.com/kb/948615

Remedy:

To restrict this warning message we need to make a entry in registry in all the client machines.

1.       Start Registry Editor.

2.       Locate and then click the following registry sub key: HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security3.       On the Edit menu, point to New, and then click DWORD Value. 4.       Type ExtensionHardening, and then press ENTER. 5.       Right-click ExtensionHardening and then click Modify. 6.       In the Value data box, type the value data, and then click OK.

 

Issue 2:

Interaction between Office Excel 2007 and Internet Explorer

When a user navigated to a Microsoft Office document from within Internet Explorer in earlier versions of the Microsoft Office suites, the document opened with the program that was hosted inside the Internet Explorer program. Many developers used this functionality to create a more integrated interaction between their Web programs and the data that was produced by those programs, such as creating a workbook and then instructing Internet Explorer to navigate to that workbook. However, this caused confusion for users who wanted to work with documents from the Web (Internet or intranet), because the full Office Excel user interface was not available from within Internet Explorer.This default behavior is changed in the 2007 Office system. The program does not open inside Internet Explorer. Instead, the appropriate Microsoft Office program launches and opens the document. This provides a more consistent experience; however, it may cause unexpected behavior in custom applications that use Internet Explorer. Although this is the default behavior, users can choose to revert to the earlier hosted behavior if that is what they prefer.

Microsoft link to refer: http://technet.microsoft.com/en-us/library/cc179188.aspx

Remedy:

·         In Windows Explorer, you click Tools, and then you click Folder Options. ·         On the File Types tab, you select a 2007 Microsoft Office file type, such as DOCX, PPTX, or XLSX, in the list of file types. ·         You click Advanced and select Browse in same window.

Thanks

Mwalter.

 


Thanks
Mahiban Walter
0
MWalter
3/4/2009 3:37:27 AM
Reply:

Similar Artilces:

Exporting Gridview Data to Excel 2007
Hi  I figured how to export the gridview data to the older version of Excel - 2003 (.xls), but need to do the export to excel 2007. I do get a prompt to open an excel spreadsheet when I click on "Open", I get the following message if I again name the file name "Something.xlsx" "Excel cannot open the file something[1].xlsx" because the file format or file extension is not valid, Verify that the file has not been corrupted and that the file extension matches the format of the file" What is the best way to export a to a xlsx file? without gettin...

GridView control exporting to Excel in Net 2.0
Well, I did my homework and found 33,868 references to issues with the gridview control and Excel, none of which were close to whats happening with my app. I have a Gridview control on my VB.NET main page and when I right click on it the popup allows me to export to Excel just fine..5-6 columns, less than 100 rows..when I do the same on another page I get an Excel error popup : "This web query returned no data.."..both grids have a (Select) button in the 1st column. The one that works is simply that...the one that doesn't has the Button.Text defined as something e...

Exporting to Excel in Crystal Reports .NET
sir,   I want to export Crystal report to Excel and the following is the code i wrote in the button click.ReportDocument rptExcel = new ReportDocument() ;string strExportFile = "C:/Session_SessionID.xls" ;rptExcel = new RptJobOrderRecap();//report namerptExcel.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile ;rptExcel.ExportOptions.ExportFormatType = ExportFormatType.Excel;ExcelFormatOptions objExcelOptions = new ExcelFormatOptions();objExcelOptions.ExcelUseConstantColumnWidth = false ;rptExcel.ExportOptions.FormatOptions = objExcelOptions ;DiskFileDestinationOp...

export gridview to excel with no formatting (formatting problem)
 Hello i am using 3rd party gridview control that is same like asp.net gridview, after export to excel, it looks ugly with no images (only gray color at inages place). All i want that either i can export it properly or leave all these formating stuff. My code to export to excel is simple, this one:string attachment = "attachment;filename=BookingList.xls"; Response.ClearContent();Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/vnd.xls";StringWriter sw = new StringWriter();HtmlTextWriter htw = new HtmlTextWriter...

EXPORT TO EXCEL NOT WORKING IN EXCEL 2007
Export to excel functionality is not working in excel 2007 but its working in earlier versions , code to export to excel contains changing mime type of response object . Is it a known bug ? Thx in advance...Giri Have a look at this thread. It will clear your doubts. http://forums.asp.net/t/1221467.aspxThanks,MaxLet Me Google That For You!...

Export To Excel Excel
Do we have any facility to export grid data in Excel with using Report Tool. Just a question, Will Response.contenet Type will work here Thanks, private void btnExportToExcel_Click(object sender,System.EventArgs e) { ExportToExcel("Report.xls",DataGrid1); } private void ExportToExcel(string strFileName,DataGrid dg) { Response.Clear(); Response.Buffer = true; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("content-disposition", "attachment;filename=" + strFileName); Response.Charset = ""; this.EnableVi...

GridView
I have a GridView that I am exporting to Excel. I need to change some of the formatting so that it renders nicely in Excel.  (It currently renders nicely on the screen.)  How can I do this? By the way, I think I have found out how to fix the "RegisterForEventValidation can only be called during Render();" error without setting the Page Directive "EnableEventValidation" to false: Before you rebind the data for the export, set the column visibility to "false" where the CRUD controls are placed. Example: In my ASPX page, I created my CommandField column first.  Now, in my co...

Export GridView to Excel 2007
I have a asp:GridView.  Is there any sample code to export this Grid View into Excel 2007. Searching everywhere on the net shows only the xls format, but not the xlsx. One posting says to use a openxmlformats content type, but that doesnt work.  I installed Office compatability pack and other downloads that the links in the discussions mentioned, but of no use. I want to write this grid to excel sheet and display it. Please help. try this link http://www.eggheadcafe.com/community/aspnet/6/10041400/reply.aspx   The above code throws an exception at this line:  ...

Export Gridview to Excel with formatting
Hello:  I can successfully export gridview to excel, but with one problem, once excel doc generated, I'd like to format the sheet, like Color, Font, Border, make column header text vertical,  etc. the gridview displays nicely but the exports excel has no formatting styles.   Please advise, thank you The code is the same if you use a gridview, just change the DataGrid to GridView  public void(Page op, DataTable dt, string psFileName)  {      DataGrid dgExport = new DataGrid();      dgEx...

Gridview export to excel with formatting
Hello I am using the code below to export gridview results to datagrid. Now I want to perform the following formmatting in the excel sheet  Rename the sheet. Change the seet from portrait to lanscape. Preserve formatting from datagrid to excel.  Any examples would be greatly appreciated!  1 Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click 2 Response.Clear() 3 Response.AddHeader("content-disposition", "attachment;filename=myexcelfile.xls") 4 5 ...

In gridview export to excel how to get colors in excel sheet
 Hello All, I am struck with a small problem here.I am displaying a gridview with some colorful rows.But when I am exporting the gridview to excel these colors are not appearing.Please give me a solution.Below i am giving the class file i used to export gridview to excel. public void ExportGridToExcel(DataSet ds, HttpResponse response,string file_name)    {        //first let's clean up the response.object        response.Clear();        response.AddHeade...

Exporting GridView data to excel or other formats...
Hi Friends, Can anyone help me exporting grid data to excel or text format. I have used the following code but it works only on a new web form and not on the form in which the grid is nested inside a table.  The code is as follows: protected void Button1_Click(object sender, EventArgs e)    {        Response.Clear();        Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");        Response.Charset = "&qu...

Exporting gridView content to excel and Formatting
Hi   I want to export the data from GridView  to Excel. I want to Format the Excel. I need the change the Header color, set  Border of the cells and merger some cells. How to format the Excel sheet with data?  How can i do that while exporting gridView content to excel? Thanks Ashok  Check this link, one of the best example http://mattberseth.com/blog/2007/04/export_gridview_to_excel_1.html   or http://www.c-sharpcorner.com/UploadFile/DipalChoksi/exportxl_asp2_dc11032006003657AM/exportxl_asp2_dc.aspx  if u find ur problem is solved Mark it has...

Issue exporting gridview control to Excel
I am using the following KB to export a gridview control to Excel. http://support.microsoft.com/kb/317719/ While this works fine for a non-ajax enabled control, if i place this insdie an Ajax application, all the controls on the page gets exported instead of just the gridview. I can attach a repro to illustrate this once i have the permission. Code Snippet: string attachment = "attachment; filename=Test.xls"; GridView1.AllowSorting = false; GridView1.AllowPaging = false;   DisableControls(GridView1);   Response.AddHeader("content-disposition", attachment); Response.Conte...

export datatable/gridview to excel with no formatting
i've searched everywhere i can think of to find how to export either a datatable or a gridview to excel with no formatting and that allows special characters, and i've come up with nothing.  every method i find has some flaw it in.  using the "Response" to export a gridview puts formatting into the excel file and renames the first sheet with the file name instead of leaving it as "Sheet1".  i tried an example from codeproject and a custom exporting dll that exports a datatable, and this one worked great exept that certain characters in my datatable ...

Export gridview to excel formatting problem
Hi all, i have in my site a page where user can create little statistics and export them to excel.The code works fine but i have a problem with formatting in particular with € symbol.This is what i find in my excel € become €à become ÃThis is my code string attachment = "attachment; filename=Ordini.xls";Response.ClearContent();Response.AddHeader("content-disposition", attachment);Response.ContentType = "application/ms-excel";StringWriter sw = new StringWriter();HtmlTextWriter htw = new HtmlTextWriter(sw);HtmlForm frm = new HtmlForm();GridView1.Parent.Control...

Gridview export to Excel with formatting #2
I have a gridview and I want to export it to an Excel doc, the gridview only receives the datasource from a datatable and binds to it. Here is my code. <asp:GridView id="gridview1" runat="server" BackColor="White" __designer:dtid="281474976710728" BorderColor="#336666" BorderWidth="3px" CellPadding="4" GridLines="Horizontal" __designer:wfdid="w2" AutoGenerateColumns="False" BorderStyle="Double"><FooterStyle BackColor="White" ForeColor="#333333" __des...

Remove formatting in Gridview excel export
Hi, I have a template field in gridview that I want to be able to export to Excel without the formatting.  The field is below : <asp:TemplateField HeaderText="Volume" SortExpression="TOTAL_VOLUME"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("TOTAL_VOLUME") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("TOTAL_VOLUME", "{0:#,# kWh}") %>&#...

GridView - Export to Excel
I have a GridView that I am exporting to Excel using the following method:  System.IO.StringWriter strWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(strWrite); Response.Clear(); Response.ContentType = "application/vnd.xls"; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("content-disposition", "attachment;filename=filename.xls"); Response.Charset = ""; gvExport.RenderControl(htmlWrite); Response.Write(strWrite.ToString()); R...

Export Datagrid value to excel sheet(Formatted excel sheet)
Hai     Export Datagrid  value to excel sheet(Formatted excel sheet). I want to copy the content of datagrid(dataset ) to excel sheet . Also i want to  change the header style(Change the background color of the header in excel sheet). Pls help me.....................

Export To Excel with formatted Text without installing excel on the server
I have the following export function to export data from datatable to excel on the client vai web browser and it works fine but I cannot add any text decoration to the strings. For example, in the code below, the first bolded section name "Header" i am trying to give the lable control with some text and color information but when i write lable with response.write it give me this "System.Web.UI.WebControls.Label" in the cell but the rest works, I need to find a way to put text decoration on the excel programmatically without having to install excel on the server....

Export GridView data in excel or any format
Hi,   I want to export gridview data in excel file or any other format. Priority excel. Any one has any code or article to this please. Using asp.net 2.0 and data is coming from SQL server 2000. Thanks http://www.gridviewguy.com/ArticleDetails.aspx?articleID=202Jared RobertsLead Application Developer make sure you add this to the top area where validation goes - EnableEventValidation="False" <script language="VB" Runat="server">   Sub doExcel(Source as Object, E as EventArgs) If grdResults.Rows.Count.ToString + 1 < 65536 Then  grdResults.AllowP...

Exporting GridView in to Excel and Text Format
hi, I want to export the data in GridView Control into an Excel Sheet (.xls) and Text (.txt) please advise...and what will be the case if the Paging is enable and gridview is having multiple pages of data. Regards In button_click event write following code.   GridView1.AllowPaging = false;   ////////write this code only if paging is enabled. GridView1.DataBind();////////write this code only if paging is enabled. Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");///////for text file write FileNam...

Gridview export to excel
Hi again, I use the following code to export contents of gridview to excel. Now the problem is that if a number is too long (say, 917894567410), excel displays it like this: 9.15403E+11. How can I fix this? Also, the color of the header fields in excel is not what it looks like in gridview. Is there a way to fix that too? protected void Button1_Click(object sender, EventArgs e) { //Response.Write(sortExpr); GridView1.AllowPaging = false; GridView1.AllowSorting = true; PopulateGridView1(); GridViewSortExpression = sortEx...

Web resources about - Export GridView to Excel (xlsx, Excel 2007 Format) - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 2/18/2016 1:40:04 AM