How to Suppress Extension Warning in Excel


I have created an Excel file from my JTable. The same button that creates it also opens it. But it gives a prompt :


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


When I click OK the file opens. I am using Office 2007 and am saving the file as .xls. Is there a way of stopping the prompt from the code level? Here is the code that creates and opens the file:

if (obj == btnExport) { File f = new File("Student Results"); f.mkdir(); try { TableModel model = DataBaseTable.getModel(); FileWriter excel = new FileWriter("Student Results/" + exam + "_"+ level + "_" + year + ".xls"); for(int i = 0; i < model.getColumnCount(); i++){ excel.write(model.getColumnName(i) + "\t"); } excel.write("\n"); for(int i=0; i< model.getRowCount(); i++) { for(int j=0; j < model.getColumnCount(); j++) { excel.write(model.getValueAt(i,j).toString()+"\t"); } excel.write("\n"); } excel.close(); JOptionPane.showMessageDialog(this, "File Exported to " + f.getAbsolutePath(), "Success", JOptionPane.INFORMATION_MESSAGE); File opn = new File("Student Results/" + exam + "_"+ level + "_" + year + ".xls"); Desktop.getDesktop().open(opn); } catch (Exception se) { JOptionPane.showMessageDialog(this, se, "Error", JOptionPane.ERROR_MESSAGE); } }


<a href="http://support.microsoft.com/kb/948615" rel="nofollow">This MSDN</a> gives a couple methods (group policy, or registry manipulation) for how you could suppress the warning, but I don't think either are particularly practical.

I would recommend making a CSV instead, since you are just writing a file. Those are also opened by Excel. I believe all you'd have to do is subsituted a comma for both of your \ts in your code.


  • 第十一章 面向对象之类的组合
  • Flutter: Pushing back button should allow the app to go to background
  • How to apply a function to pairs of rows in a data.frame, similar to diff?
  • Is it a good practice to user Fragment.setRetainInstance to not handle recreation?
  • How to detect if MediaRecorder is used by another application?
  • IntelliJ does not find native libraries for OpenCV when adding jar as a dependency for Play project
  • java.lang.UnsupportedOperationException: getRowData(String rowKey) must be implemented when basic ro
  • Checking instance of non-class constrained type parameter for null in generic method
  • How to optimise bootstrap to avoid rendering unused css code
  • Should authentication be in a separate service for wcf?
  • How to get selected text using android spinner wheel?
  • Angular $resource is not working
  • Export a simple Dictionary into Excel file in python
  • How can I access the Google account user_id?
  • How to use CoreFoundation in QuickTime SDK for Windows?
  • Custom Data Generator for Keras LSTM with TimeSeriesGenerator
  • In metro, get all inherited classes of an (abstract) class?
  • How to change the host IP sent in emails to new GitLab users to a publicly visible IP, not the local
  • How to use array in autohotkey?
  • Magento-Change Attribute of All Products
  • Create an average of multiple excel chart without the data source
  • Comparing variables with strings bash
  • how to run ejabberd with Erlang on Heroku?
  • How to use Streams api peek() function and make it work?
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • How to handle div that is created dynamically in a table
  • Make checkout phone field optional for specific countries in WooCommerce
  • Jersey serializes character value to ASCII equivalent numeric string
  • WPF custom control and direct content support
  • ReferenceError: TextEncoder is not defined