java - The fomat and extension of "file.csv" doesn't match
问题描述
I am trying to create the csv file with data as follows
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sheet1");
String fileLocation = null;
try {
// Set the header columns name for worksheet
createHeader(workbook, sheet);
// populate the data
createWorkbookRows(ker, sheet, kerList, AerList);
String tempDir = System.getProperty("java.io.tmpdir");
File file = new File(tempDir);
fileLocation = file.getAbsolutePath() + FileSystems.getDefault().getSeparator() + "MyData.csv";
FileOutputStream outputStream = new FileOutputStream(fileLocation);
workbook.write(outputStream);
}catch(Exception e){
}
With the above code I am able to generate the csv file, but when I try to open the file the below error it is showing
When I click on yes
it is showing the data properly in excel file.
I have verified the csv file by opening in Notepad++
also it is showing in non understandable language instead of comma seperated.
Please suggest how can I solve the above issue.
解决方案
POI writes a binary Excel file. Your extension "csv" is wrong. It should be "xlsx" because you use XSSFWorkbook.
推荐阅读
- xml - 如何在 .sumocfg (SUMO) 中添加多个附加文件?
- jquery - Instagram Feed - 用于 Instagram 的 jQuery 插件在新窗口中打开
- azure-aks - terraform azurerm_kubernetes_cluster 节点
- sql - 在 Case when 子句中遍历其他表
- docker - 设置本地 Selenium 项目以在 Docker 容器上安装 Jenkins 运行
- c# - 创建上划线文本
- ruby-on-rails - 通过 ActionCable 发送 zip 二进制数据
- java - Java:While Loop 抑制 JFrame 的绘制功能
- java - Osmdroid -NullPointerException: Attempt to invoke virtual method 'boolean org.osmdroid.views.overlay.Overlay.onTouchEvent
- c# - number formatting in asp.net markup code?