我的文件下载有'PK z—;LO‹Ý<_rels/.rels<;?xml vers…`在前端

我的文件下载有'PK z—;LO‹Ý<_rels/.rels<;?xml vers…`在前端,xml,angular,typescript,blob,Xml,Angular,Typescript,Blob,我下载文件时遇到了问题 我下载包含以下文本的文件: PK z—LO‹Ý< _rels/.rels<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Target="word/document.xml" Id="pkgR

我下载文件时遇到了问题

我下载包含以下文本的文件:

PK
     z—LO‹Ý<       _rels/.rels<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Target="word/document.xml" Id="pkgRId0" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" /></Relationships>PK
     z—LÜó À–  –     word/_rels/document.xml.rels<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Target="numbering.xml" Id="docRId0" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" /><Relationship Target="styles.xml" Id="docRId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" /></Relationships>PK
     c…˜Lx»s/  /     word/document.xml<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:pPr><w:spacing w:before="0" w:after="200" w:line="276" /><w:ind w:right="0" w:left="0" w:firstLine="0" /><w:jc w:val="left" /><w:rPr><w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Calibri" w:eastAsia="Calibri" /><w:color w:val="auto" /><w:spacing w:val="0" /><w:position w:val="0" /><w:sz w:val="24" /><w:shd w:fill="auto" w:val="clear" /></w:rPr></w:pPr><w:r><w:rPr><w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:cs="Calibri" w:eastAsia="Calibri" /><w:color w:val="auto" /><w:spacing w:val="0" /><w:position w:val="0" /><w:sz w:val="72" /><w:shd w:fill="auto" w:val="clear" /></w:rPr><w:t xml:space="preserve">test</w:t></w:r></w:p></w:body></w:document>PK
     z—L,1¿q         word/numbering.xml<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:numbering xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" />PK
     z—L¯SÈAŠ   Š      word/styles.xml<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" />PK
     z—Lÿbkº]  ]     [Content_Types].xml<?xml version="1.0" encoding="UTF-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" /><Default Extension="xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" /><Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml" /><Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" /></Types>PK
     c…˜L               word/PK 
     z—LO‹Ý<                     _rels/.relsPK 
     z—LÜó À–  –               E  word/_rels/document.xml.relsPK 
     c…˜Lx»s/  /                 word/document.xmlPK 
     z—L,1¿q                   s  word/numbering.xmlPK 
     z—L¯SÈAŠ   Š                0  word/styles.xmlPK 
     z—Lÿbkº]  ]               ç  [Content_Types].xmlPK 
     c…˜L                        u   word/PK      ³ 
我的html代码:

  <button>
<i class="fa fa-save" aria-hidden="true"(click)="exportExcel(item.sale_id)"></i>
  </button>


求你了,我需要你的支持。谢谢

开头的
PK
告诉您,这是一个压缩文件。尝试使用7-zip或任何其他解压缩工具打开此文件

zip格式是由
p
hil
K
atz创建的(“zip”以前被称为“PKWARE”):-D

Jeroen Mostert是对的:现代Excel文件(
.xlsx
)是压缩文件。将扩展名更改为
.zip
可以在Explorer中像打开任何其他zip文件一样打开这样的文件


您可以在目录
xl
中找到工作表的数据,如
sheet1
sheet2
PK
是最新版本的Excel确实使用zipfiles作为其数据格式。你下载的不是纯文本,所以这是正确的。生成的文件能否在Excel中打开?如果不是,二进制数据在传输到服务器时可能会因编码问题而被损坏,或者服务器的
内容类型
在响应中出错。@Jeroenmoster我完全忽略了这是关于Excel的,只是看到了“PK”并想:哦,是的@Shnugo:别难过,我几乎写了一些关于使用
内容编码:identity
来抑制服务器压缩的东西,然后我才想起zip和gzip是不相关的……哦,不,真的:(我不相信。谢谢。当我试着邮递这个wm时,功能正常,下载我的file.txt,但代码不是。另外,我试过这个
people export.xlsx
people export.zip
,现在有一些文件,但不是我想要的我的文件。你知道吗?@OnnaB你可以将它导出为逗号分隔格式(Excel可以以本机方式打开此类CSV文件)。否则,您必须了解给定的格式,创建一个格式正确的包,并将其存储为扩展名为
.xlsx
的压缩文件。但这并不是一件小事。在开始开发之前,我会尝试从中找到一些东西:-请,您能问我一些示例,如何将此文件转换为pdf格式并使用真实数据吗?我尝试了一些e例如,但什么也没发生。是的,我写了一个新问题:但没有答案:(
  exportExcel(id: string) {
    this.ss.download(id)
      .subscribe(data => { console.log(`excel data: ${data}`); FileSaver.saveAs(data, 'people-export.xlsx') },
        error => console.log("Error downloading the file."),
        () => console.log('Completed file download.'));
  }
  <button>
<i class="fa fa-save" aria-hidden="true"(click)="exportExcel(item.sale_id)"></i>
  </button>