创建新的POI工作簿但不保存它

时间:2016-06-30 13:50:06

标签: java apache-poi

是否可以让Apache POI创建并打开一个新的Excel工作簿文件,但不一定将保存作为文件?我试图将其作为短期文件打开,就像从互联网上下载一样,以便在需要时可以保存,但以其他方式删除。

1 个答案:

答案 0 :(得分:3)

没有。 Excel打开文件。即使您打开的“已从Internet下载”的文件也会临时保存到指定的下载目录或用户的临时目录中。

您可以将工作簿保存在用户的临时目录中(请参阅Files.createTemporaryFile()),并仅在用户决定永久保留后再移动或复制它。如果他们不想保留,您可以立即使用File.delete()或使用File.deleteOnExit()退出应用程序时将其删除。

请注意,在Windows上,如果您确保应用程序在尝试删除这些文件及其关联的流之前关闭这些文件及其关联的流,则new Vue({ el: '.container-fluid', data: { location: "", temperature: "", degree: "C", weather: "", iconURL: "" }, created: function(){ this.getWeather(); }, methods: { getWeather: function(){ var that = this; this.$http.get("http://ipinfo.io").then((response) => { console.log(response.data); that.location = response.data.city + ", " + response.data.country; // Get weather informaiton var api = 'ebd4d312f85a230d5dc1db91e20c2ace'; var city = response.data.city; var url = "http://api.openweathermap.org/data/2.5/weather?q={CITY}&APPID={APIKEY}&units=metric"; url = url.replace("{CITY}",city); url = url.replace("{APIKEY}", api); that.$http.post(url,{dataType: 'jsonp'},{ headers : { 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8' }}).then((response) => { console.log(response.data); that.temperature = response.data.main.temp; that.weather = response.data.weather[0]['description']; that.iconURL = "http://openweathermap.org/img/w/" + response.data.weather[0]['icon'] + ".png"; }, (response) => { // error callback }); }, (response) => { console.log(response.data); }); }, changeDegree: function() { if(this.degree == "C"){ this.degree = "F"; this.temperature = Math.round((this.temperature*9/5 + 32)*100)/100; }else { this.degree = "C"; this.temperature = Math.round(((this.temperature - 32)*5 /9)* 100)/100; } } } }) File.delete()只会一致地工作。 try-with-resources statement对此非常有帮助。

相关问题