Conversion of Base64 Encoded into XSLX

14,699

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.

Share:
14,699
Gerorge Timber
Author by

Gerorge Timber

Updated on June 04, 2022

Comments

  • Gerorge Timber
    Gerorge Timber almost 2 years

    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 there was stream of Base64 encoded Code. Initially the content-type was Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;

    Now, Is it possible to convert the base-64 encoded string code to retrieve the xslx document? I tried using several online sites like base64decode.org but as the initial file type was xslx, it didn't gave any output in Plain-Text too. So how do i work out with issue ?

  • Gerorge Timber
    Gerorge Timber over 7 years
    But the File format is in xslx not plain text. This decode probably gives plain text isn't it ?
  • LinuxDisciple
    LinuxDisciple over 7 years
    @GerorgeTimber check out my new answer. It's a tool.