如何在Excel中禁止扩展警告 [英] How to Suppress Extension Warning in Excel

查看:423
本文介绍了如何在Excel中禁止扩展警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从我的JTable创建了一个Excel文件。创建它的同一个按钮也会打开它。但是它会提示:


您尝试打开的文件的格式与
指定的文件扩展名不同。在打开文件之前,验证该文件是否已损坏,并且来自
信任用户。您要打开文件吗?


当我单击确定打开文件。我正在使用Office 2007,并将文件另存为 .xls 。有没有办法从代码级别停止提示?以下是创建并打开文件的代码:

  if(obj == btnExport){
File f =新文件(学生成绩);
f.mkdir();
try {
TableModel model = DataBaseTable.getModel();
FileWriter excel = new FileWriter(Student Results /+ exam +_+ level +_+ year +.xls); (int i = 0; i< model.getColumnCount(); i ++){
excel.write(model.getColumnName(i)+\t);

}

excel.write(\\\
); (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(\\\
);
}

excel.close();
JOptionPane.showMessageDialog(this,File exported to+ f.getAbsolutePath(),
Success,JOptionPane.INFORMATION_MESSAGE);
文件opn = new File(Student Results /+ exam +_+ level +_+ year +.xls);
Desktop.getDesktop()。open(opn);

} catch(异常se){
JOptionPane.showMessageDialog(this,se,
Error,JOptionPane.ERROR_MESSAGE);
}
}


解决方案

a href =http://support.microsoft.com/kb/948615 =nofollow>此MSDN 提供了几种方法(组策略或注册表操作),以便如何抑制警告,但是我不认为这两者都是特别实用的。



我建议使用CSV,因为你只是写一个文件。那些也是由Excel打开的。我相信你所需要做的就是在您的代码中为您的 \t 中的一个逗号。


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);
  }
}

解决方案

This MSDN 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.

这篇关于如何在Excel中禁止扩展警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆