Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8534845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:17:28+00:00 2026-06-11T10:17:28+00:00

I am trying to export data from database to excel 2007 file. I just

  • 0

I am trying to export data from database to excel 2007 file.

I just want to change the header of html file to excel 2007 file.

I format the data into a table and change the header to this:

Response.AddHeader("Content-Disposition", "attachment;filename= filename.xlsx");
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

I keep getting the same error:

“Excel cannot open the file “filename.xlsx’ because the file format of
file extension is not valid. Verify that the file has not been
corrupted and that the file extension matches the format of the file”

I also tried this example i found online and i can open in excel 2003 with a warning message, but on 2007 i get the above error message. It need to make it work with excel2007

<html 
xmlns:o="urn:schemas-microsoft-com:office:office" 
xmlns:x="urn:schemas-microsoft-com:office:excel" 
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:Selected/>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml><![endif]-->
<style>
<!--table
    {mso-displayed-decimal-separator:"\.";
    mso-displayed-thousand-separator:" ";}
.xl2
    {
    mso-number-format:M/D/YY;
    border-left:.5pt solid;
    border-top:.5pt solid;
    border-right:.5pt solid;
    border-bottom:.5pt solid;
    }
.xl3
    {
    border-left:.5pt solid;
    border-top:.5pt solid;
    border-right:.5pt solid;
    border-bottom:.5pt solid;
    }
-->
</style>
</head>
<body>
<table>
<tr>
<td class=xl2>17.02.2010</td>
<td class=xl3>4</td>
<td class=xl3>0</td>
</tr>
<tr>
</tr>
</table>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:17:29+00:00Added an answer on June 11, 2026 at 10:17 am

    I use this form :

    using(System.IO.MemoryStream ms = /*Include Excel File*/) {
      ControllerContext.HttpContext.Response.Clear();
      ControllerContext.HttpContext.Response.AddHeader("cache-control", "private");
      ControllerContext.HttpContext.Response.AddHeader("Content-disposition", "attachment; filename=" + filename + ";");
      ControllerContext.HttpContext.Response.AddHeader("Content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
      ms.WriteTo(ControllerContext.HttpContext.Response.OutputStream);
    }
    return null;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to export data from a database into a set format so that
I am trying to export data from database to an excel sheet, using php
I'm trying to export data from an Excel spreadsheet into a fairly complex relational
I'm trying to export data from a web app into excel, but there is
I'm trying to export data from a multivalue database (Unidata) into MySQL. Lets say
In my application I am trying to export the data from the <h:DataTable> into
I am trying to make an xml file to export my data from my
I'm trying to export some data from MATLAB to a database. I use a
I'm trying to import data from a Progress database into a MS SQL 2005
I am trying to import data from a column in a .xslx file into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.