Conversion of Base64 Encoded into XSLX

后端 未结 1 1442
隐瞒了意图╮
隐瞒了意图╮ 2021-01-03 13:10

I was looking into my Mail Server in Text version; There is saw an attachment of filename= xyz.xslx & Content-Transfer-Encoding: base-64 and after that ther

相关标签:
1条回答
  • 2021-01-03 14:08

    Try using the snippet below to download your base64 string as an xlsx file.

    Read on for instructions. `

    function saveAsXlsxFile(){
      var pre="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,";
      var inp = document.getElementById('base64input');
      var anchor = document.getElementById('stuff');
      anchor.href=pre+inp.value;
      anchor.style.display="block";
    }
    <a id="stuff" href="" style="display:none" >Click here to download as an xlsx file</a>
    <input placeholder="paste the base64 data here, exclude readable headers" id='base64input' type="text"><br>
    <input onclick="saveAsXlsxFile()" type="button" value="update content of link"></button>

    ` I made an XLSX file, imported it into the browser with JavaScript. It starts like this:

    "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,UEsDBBQABgAIA
    

    We want to ignore anything that looks like the beginning part (the readable stuff) and only copy the base64 data string (the part beginning with UEsDBBQABgAIA in my example, though yours may start with something different). It's going to be a very long string; even an empty file is almost 10k.

    Copy that big long base64 data string (exclusive of any headers similar to the non-bold part from above) and paste it into the input field in the snippet.

    You should get a link that lets you download it as an xlsx file.

    If you get a garbled file, make sure you didn't accidentally paste input that had newlines inserted from line wrapping, and keep in mind that the last few chars of the base64 string could be characters like = and it's important to include every character.

    Give it a shot and let me know how it goes.

    0 讨论(0)
提交回复
热议问题