Lets Learn

Opinion Matters

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 8 other followers

  • Blog Stats

    • 73,707 hits
  • Ankush

    Error: Twitter did not respond. Please wait a few minutes and refresh this page.

Excel Warning Message

Posted by Ankush on October 5, 2009


Hi Guys,

This is my first blog and today I write about a new security feature which has been added onto Excel 2007 and is named Extension Hardening.

When you open a file in Microsoft Office Excel 2007 that has content, it does not match the file’s extension; you receive the following warning message:

The file you are trying to open, ‘abc.xyz’, 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?

Note: abc.xyz is the file name that you are trying to open in Excel.

Once this warning is displayed, then a user can decide whether he/she wants to open the file or not.  However this warning can be set to different levels via the registry editor.  You can check/set the settings as per the following:

  • Click Start, Run, type regedit, and then click OK.
  • Locate and then click the following registry subkey: HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security
  • On the Edit menu, point to New, and then click DWORD Value.
  • Type ExtensionHardening, and then press ENTER.
  • Right-click ExtensionHardening, and then click Modify.

 In the Value data box, type the value data, and then click OK.
 
The following list contains the value data settings that are appropriate for the ExtensionHardening setting:

Value data

Warning Message

0 Do not check the file name extension and the file type, and bypass the function of the warning message
1 Check the file name extension and the file type. If they do not match, display the warning message.  
2 Check the file name extension and the file type. If they do not match, do not open the file. 

Default setting if value not present is 1 (enable and prompt).If this key is not present, you will see the dialog similar in case of Value data 1.

 Please have a look at the different warnings. Depending upon the value data, you get the option whether you can bypass the message and open the file or not.

Note: If user gets the warning message and you don’t see the ExtensionHardening key under  HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security, then also check at HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\12.0\Excel\Security

Now I have explained about the ExtensionHardening warning, let’s see how we can bypass it.

One easy method is change the registry and set the value data to 0. But if changing the registry is not possible then  ?????

To bypass this, we need to understand a little bit about this concept. Basically this warning comes when you generate the Excel file on the fly/export the content of a dataset as an Excel 2007 file and end user will open the file in excel 2007. So we need to change the underlying logic to generate the Excel file so that content of the file and the extension does match.

So let’s summarize, how we can do this:

  • CSV file: This is handy when you just want to put the data.
  • Generate an XML file: Generate a proper spreadsheet XML
  • Generate from GridView: Export the data as an Excel file.
  • Generate an Excel file using the Open XML SDK 2.0: Use Open XML SDK to generate the file.
  • Excel ADO: If you have a template, then using this approach, you can simply connect to the file and insert records.
  • Excel PIA’s: DO NOT use the Excel PIAs to generate a spreadsheet server-side. It’s not supported so don’t go on this route. For more information, refer: http://support.microsoft.com/kb/257757

In my upcoming blog I will write about every approach in detail with some sample codes.

So watch this space for some more …

Let me know what you think, things that I can include and if you have questions.

Advertisements

2 Responses to “Excel Warning Message”

  1. Terry Jackson said

    Ankush, did you ever write about the recommended approaches listed above to bypass the extension hardening in Office 2010? (aside from manipulating the setting through the registry)

  2. Ankush said

    You can also set this via policy. An admin can easily perform this task.

    However, the main thing is, you need to generate the Excel file in such a way where content of the file and the extension does match.

    Thanks,
    Ankush

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: