My file download have ` PK z—LO‹Ý< _rels/.rels<?xml vers…` in front end

喜欢而已 提交于 2019-12-11 14:50:07

问题


I have the problem when I download the file.

I download the file with this text:

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      ³ 

In fact this is not the text that I want to download.

I tried this code: my service code:

  public download(id: string): Observable<any> {
    let params = new URLSearchParams();
    let headers = new Headers();
    headers.append('x-access-token', this.auth.getCurrentUser().token);
    headers.append('sale_id', id);
    headers.append('Content-Type', 'text/xml');
    headers.append('responseType', 'blob');
    return this.http.get(Api.getUrl(Api.URLS.download), {
      headers: headers,
     responseType: ResponseContentType.Blob,
    }).map(res => res.blob())
  }

my component code:

  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.'));
  }

my html code:

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

Please, I need your support. Thank you


回答1:


The PK at the beginning tells you, that this is a zipped file. Try to open this file with 7-zip or any other unzipping tool.

The zip-format was created by Phil Katz ("zip" was formerly known as "PKWARE") :-D

Jeroen Mostert is right: Modern Excel files (.xlsx) are zipped files. Changing their extension to .zip allows to open such a file within Explorer just as any other ZIP-file.

You find the Worksheet's data within the directory xl as sheet1 or sheet2



来源:https://stackoverflow.com/questions/50005473/my-file-download-have-pk-z-lo-%c3%9d-rels-relsxml-vers-in-front-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!