Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Excel可以打开的制表符分隔值的文件扩展名?_Spring_Excel_Download_File Extension_Tab Delimited - Fatal编程技术网

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

Spring Excel可以打开的制表符分隔值的文件扩展名?,spring,excel,download,file-extension,tab-delimited,Spring,Excel,Download,File Extension,Tab Delimited,我正在从我的webapp输出一个制表符分隔的文件,该文件应该在Excel中打开。问题是.xls似乎不适合打开和编辑它,然后Excel需要其他格式,如果我将扩展名更改为.tsv,则Excel(在Windows 7上)将无法识别该文件,.csv表示逗号分隔的文件。你能告诉我文件扩展名应该是什么吗 这是输出文件并正常工作的代码。只是我应该为制表符分隔的值选择最合适的扩展名 @RequestMapping(value = "/export", method = RequestMethod.GET) @R

我正在从我的webapp输出一个制表符分隔的文件,该文件应该在Excel中打开。问题是.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;
}
@RequestMapping(value=“/export”,method=RequestMethod.GET)
@应答器
公共模型和视图导出(HttpServletResponse){
试一试{
字符串str=“”;
迭代器迭代器=customerAccountService.getAllIndividuals().Iterator();
while(iterator.hasNext()){
单个=迭代器.next();
str=str+individual.getId()+“\t”+individual.getIndividualName().getName()+“\t”+individual.getAddress().getStreetName()+“\n”;
}
InputStream is=newbytearrayinputstream(str.getBytes());
copy(is,response.getOutputStream());
response.setContentType(“应用程序/xls”);
setHeader(“内容处置”、“附件;文件名=export.tsv”);
response.flushBuffer();
}捕获(IOEX异常){
//logger.info(“将文件写入输出流时出错。文件名为”“+Filename+””);
抛出新的RuntimeException(“将文件写入输出流时出错”);
}
ModelAndView ModelAndView=新建ModelAndView(ViewName.MENU);
modelAndView.addObject(ObjectName.ADD_表单,new LoginForm());
返回模型和视图;
}
Put

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

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

sep=     (an actual tabulator character here, it's just not visible...)

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

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

sep=     (an actual tabulator character here, it's just not visible...)

你在这里的回答解决了我在这里遇到的问题:-在我的问题上写下答案,我会给你奖金。这是正确的答案。我将这一行添加到我的制表符分隔文件(在bash脚本中使用wget下载)的开头,然后简单地运行“open”,excel理解这是一个TDF,并正确显示了数据+1@touson很高兴我能帮忙!请注意,这不是CSV的标准化功能,因此,如果您使用Microsoft Excel以外的任何工具,它可能无法工作。您在此处的答案解决了我在此处遇到的问题:-请在我的问题上下拉一个答案,我将奖励您奖金。这是正确的答案。我将这一行添加到我的制表符分隔文件(在bash脚本中使用wget下载)的开头,然后简单地运行“open”,excel理解这是一个TDF,并正确显示了数据+1@touson很高兴我能帮忙!请注意,这不是CSV的标准化功能,因此,如果您使用Microsoft Excel以外的任何工具,它可能无法工作。