xlsx文件格式无效

时间:2018-06-06 08:02:26

标签: asp.net-mvc export-to-excel system.io.file

我使用System.IO在Excel中导出报表。它适用于.xls扩展名,但是当我将扩展名更改为.xlsx时,它会出现错误,即扩展名不正确或文件格式不正确。

private final UpdateSynchronizer synchronizer = new UpdateSynchronizer();

// why did all the keywords start with uppercase letters (compile time error)
private void handleEvent(){
  TableView.setRowFactory(new Callback<TableView<myModel>, TableRow<myModel>>(){
    public TableRow<myModel> call(TableView<myModel> p) {
      final TableRow row = new TableRow();
      row.setOnDragDetected(new EventHandler<MouseEvent>(){
        public void handle(){
           synchronizer.lock();
           //implement some kind of lock to prevent receiving data update
        }
      }
      row.setOnMouseDragExited(new EventHandler<MouseDragEvent>(){
        //release lock to accept update
        synchronizer.unlock();
      }
   }
}

//this method is being called externally periodically
public void updateModel(myModel model){
  synchronizer.runUpdate(() -> {
      // this is just an assignment and won't have any side effects
      // updates to the scene may only happen, if the model is accessed in some event handler or animation
      this.model = model;

  });
}

有什么问题?

1 个答案:

答案 0 :(得分:1)

问题在于htmlxls还是xlsx

对于xls作为过时格式,Excel会尝试修复您的问题并检查它支持的所有格式:

screensot

但是xlsx应该是zip,里面有一些xml,所以消息不同:

screenshot

您必须使用相应的库来创建真实的Excel文件。