Excel 可以打开的制表符分隔值的文件扩展名?

Nik*_*ntz 1 excel spring file-extension download tab-delimited

我正在从应该在 Excel 中打开的 webapp 输出一个制表符分隔的文件。问题是 .xls 似乎不适合打开和编辑它,然后 Excel 需要一些其他格式,如果我将扩展名更改为 .tsv,那么该文件对于 Excel(在 Windows 7 上)变得未知,而 .csv 用于逗号 -分开了。你能告诉我文件扩展名应该是什么吗?

这是输出文件的代码,它可以工作。只是我应该为制表符分隔值选择最合适的扩展名。

@RequestMapping(value = "/export", method = RequestMethod.GET)
@ResponseBody
public ModelAndView export(HttpServletResponse response) {
    try {
        String str = "";
        Iterator<Individual> iterator = customerAccountService.getAllIndividuals().iterator();
        while(iterator.hasNext()){
            Individual individual = iterator.next();
            str = str + individual.getId() + "\t" +individual.getIndividualName().getName() + "\t" + individual.getAddress().getStreetName() + "\n";
        }
        InputStream is = new ByteArrayInputStream(str.getBytes());
        IOUtils.copy(is, response.getOutputStream());
        response.setContentType("application/xls");
        response.setHeader("Content-Disposition","attachment; filename=export.tsv");
        response.flushBuffer();
    } catch (IOException ex) {
        //logger.info("Error writing file to output stream. Filename was '" + fileName + "'");
        throw new RuntimeException("IOError writing file to output stream");
    }
    ModelAndView modelAndView = new ModelAndView(ViewName.MENU);
    modelAndView.addObject(ObjectName.ADD_FORM, new LoginForm());
    return modelAndView;
}
Run Code Online (Sandbox Code Playgroud)

sin*_*ina 7

sep=\t
Run Code Online (Sandbox Code Playgroud)

作为 .csv 文件中的第一行(是的,您可以将其命名为 .csv)。这告诉 excel 分隔符应该是什么。

请注意,实际上如果您使用文本编辑器打开 .csv,它应该像

sep=     (an actual tabulator character here, it's just not visible...)
Run Code Online (Sandbox Code Playgroud)