-1

I have an app which converts jTable instances into an excel file. In my previous question, I had a problem in using FileOutputStream() and it turns out that the problem lies within the AD user's privilege in accessing folders/files. Since my superior wont allow me to change the privileges, I resorted using the FileWriter() instead, which worked well. The only problem is that it kept on warning the users that the file they are opening is corrupt. Here's the warning:

The file you are trying to open, 'filename.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?

I searched for a solution which resides in Excel 2007's file extension security. Info can be found here

I made some configuration in the system registry of every workstation that the app covers.

I just want to ask if there's a away to remove the corrupt file warning in Office 14, because one of the workstation, which is my superior's workstation, has Office 14. The changes in the system registry didnt stop the corrupt file warning in his workstation.

Jaycroll
  • 9
  • 2
  • What is the format that you write the file? if it is a simple excel file with no formatting, you can simply use a comma separated value file with an extension ".csv". – Helium Jun 05 '12 at 10:05

1 Answers1

3

I get the impression that you are indulging in "voodoo programming" practices; i.e. applying solutions that you don't understand to problems that you don't understand.

Firstly, this:

I had a problem in using FileOutputStream() and it turns out that the problem lies within the AD user's privilege in accessing folders/files. Since my superior wont allow me to change the privileges, I resorted using the FileWriter() instead, which worked well.

Frankly, this doesn't make sense. If you cannot open a file using new FileOutputStream(File), then you shouldn't be able to open it with new FileWriter(File). Why? Because the source code for the constructor is this:

    public FileWriter(File file) throws IOException {
        super(new FileOutputStream(file));
    }

In other words, the first thing that the FileWriter constructor does is to call the FileOutputStream constructor that you say doesn't work!! (And the same applies to the other overloads of these constructors.)

Then your current problem is really about Excel not letting you open an XLS file because its filetype doesn't match its suffix. And your proposed solution is to mess around with the registry. But surely, the CORRECT approach is to find out why the file type doesn't match the suffix.

  • Have you made a mistaKe in the file format (e.g. 'cos you wrote it using a FileWriter)?
  • Have you chosen the wrong file suffix for the spreadsheet format you've used?
  • Are you downloading it to the user's machine with the wrong MIMEtype?

Banging on the registry on all of the client machines ... just because you read it in some website ... that's Voodooo!

I'm not surprised that your boss forbade you to mess around with AD privileges. At this point, he's probably worried that you'll do serious damage.


By the way, your registry hacking to make the warning go away is actually turning off a security check that is designed to help harden the user's PC against attack. That doesn't strike me as a sound solution to your problem.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216