title: Using Angular 2 to generate a Docx Files
body: <p>I am using angular2 and I want to generate a docx file using an object. I want my docx file to contain footers, headers, tables etc. The best solution i can come up with is first creating an HTML file, then converting it to docx file. But this does not seem right. Is there an easier and more convenient way to do what I want to do? Here is the method I use:</p>
  
  <pre><code>exportAsDoc() {
  
  const preHtml = '&lt;html xmlns:o=\'urn:schemas-microsoft-com:office:office\' ' + '' +
          ' xmlns:w=\'urn:schemas-microsoft-com:office:word\' xmlns=\'http://www.w3.org/TR/REC-html40\'&gt;&lt;head&gt;&lt;meta charset=\'utf-8\'&gt;' +
          '&lt;title&gt;Export HTML To Doc&lt;/title&gt;&lt;/head&gt;&lt;body&gt;';
  const postHtml = '&lt;/body&gt;&lt;/html&gt;';
  
  let innerHtml = '';
  // Specify file name
  const filename = this.respSheet.title + '.doc';
  const respSheetKpis = this.respSheet.sheet_kpis;
  respSheetKpis.forEach(x =&gt; {
    const footer = '&lt;p style="text-align: center"&gt;' + x.kpi.name + ' - ' + x.kpiValue + '&lt;/p&gt;';
    innerHtml += footer;
    x.sheet_kpi_dimensions.forEach(dimension =&gt; {
      if (dimension.dimension !== undefined) innerHtml += dimension.dimension.name;
      let table = '&lt;table&gt;\n' +
              '  &lt;tr&gt;\n' +
              '    &lt;th&gt;Istatistik adi&lt;/th&gt;\n' +
              '    &lt;th&gt;Degeri&lt;/th&gt; \n' +
              '  &lt;/tr&gt;\n';
      const data = dimension.data;
      if (data !== undefined) {
        for ( let i = 0 ; i &lt; data.length ; i ++ ) {
          table += ' &lt;tr&gt;\n' +
                  '    &lt;th&gt;' + data[ i ].title + '&lt;/th&gt;\n' +
                  '    &lt;th&gt;' + data[ i ].value + '&lt;/th&gt; \n' +
                  '  &lt;/tr&gt;\n';
        }
        table += '&lt;/table&gt;';
        innerHtml += table;
      }
    })
  });
  const html = preHtml + innerHtml + postHtml;
  
  const blob = new Blob(['\ufeff', html], {
    type: 'application/msword'
  });
  
  // Specify link url
  const url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(html);
  
  // Create download link element
  const downloadLink = document.createElement('a');
  
  document.body.appendChild(downloadLink);
  
  if (navigator.msSaveOrOpenBlob ) {
    navigator.msSaveOrOpenBlob(blob, filename);
  } else {
    // Create a link to the file
    downloadLink.href = url;
  
    // Setting the file name
    downloadLink.download = filename;
  
    // triggering the function
    downloadLink.click();
  }
  
  document.body.removeChild(downloadLink);
  </code></pre>
  
  <p>}</p>