Reputation: 758
I'm exporting my grid to excel with a normal onRequestStart function in JS (here is the function)
<script type="text/javascript">
function onRequestStart(sender, args) {
if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {
args.set_enableAjax(false);
}
}
</script>
then I'm calling on Grid_ItemCommand an checking if it is a excel export word or csv then im calling my method doExport()
private void doExport()
{
this.UserGrid.ExportSettings.ExportOnlyData = true;
this.UserGrid.ExportSettings.IgnorePaging = true;
this.UserGrid.ExportSettings.OpenInNewWindow = true;
this.UserGrid.ExportSettings.FileName = String.Format("YearReport_{0}_{1}", this.selectedYear, this.rcbDepartments.SelectedValue);
}
And everything is working perfectly so far , but after finish downloading the file and opening in excel a strange > "Warring Message" arrived is there a solution how to disable this message ?
Thanks for help and fast answer
PS:If you need something more feel free to ask
Upvotes: 0
Views: 5288
Reputation: 440
I'm currently working on a programmatic way of doing this with c#. Outside of c# if you're just trying to open the file from your file system on windows you can modify the registry to ignore it.
I'll follow up with my programmatic solution, if I get it.
Upvotes: 0
Reputation:
I think the problem is that this grid component is exporting it to html and just add a xlsx tag or what ever so excel in 2010 has this new mechanism that is protecting excel to open unknown files I think for my self there is no solution for that problem ..
Upvotes: 1
Reputation: 9126
This error occurs because of creating the Excel file using Mime Type
not by Microsoft.Office.Interop.Excel
,
Cause of this Error :
The alert is a new security feature in Excel 2007 called Extension Hardening, which
ensures that the file content being opened matches the extension type specified in the
shell command that is attempting to open the file. Because the MIME types listed above are
associated with the .XLS extension, the file must be in XLS (BIFF8) file format to open
without this warning prompt. If the file type is a different format (such as HTML, XML,
CSV, etc.) the prompt is expected since the file content is different that the extension
or MIME type. The alert is first seen when opening the file from a URL site directly. If
you cancel the alert, the open will fail, but then IE will attempt to download the file
and open again using a different shell command. Depending on what the file contents is and
what extension IE gives the file it downloads, you may see the second open attempt
succeed, or you may see the prompt again but with a different filename in the alert dialog.
The alert prompt is "by design", but the interaction of the cancel action and IE's
attempt to open the file again is a known problem under investigation for a future fix.
Explanation Source : http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx
Upvotes: 2
Reputation: 1427
Save the export file as a ".xlsx" file. This happens all the time when you save an Office 2003 style as .xlsx or the other way around.
Edit
Or as mentioned in the other answer, ".csv". The same concept applies.
Excel detects that the file content doesn't match given extension, hence the error.
Upvotes: 2
Reputation: 63956
The problem is the mismatch between the actual file type and the extension because you are exporting the data as CSV yet you are telling Excel that it's an XLS file. This is a normal Excel warning.
If you want to disable this, just make sure that the file exported has the "csv" extension instead.
Upvotes: 3