Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Whats up folks,

my question is actually not how is such a thing done (cause I've already a code snippet) but my question is how do I set a name for the file which I create...

The code I have...

var tableToExcel = 
(
function() 
{
    var uri = 'data:application/vnd.ms-excel;base64,';
    var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'

    /* ... here again just as comment to overview it better...
    <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
    <head>
    <!--[if gte mso 9]>
        <xml>
            <x:ExcelWorkbook>
                <x:ExcelWorksheets>
                    <x:ExcelWorksheet>
                        <x:Name>
                            {worksheet}
                        </x:Name>
                        <x:WorksheetOptions>
                            <x:DisplayGridlines/>
                        </x:WorksheetOptions>
                    </x:ExcelWorksheet>
                </x:ExcelWorksheets>
            </x:ExcelWorkbook>
        </xml>
    <![endif]-->
    </head>
        <body>
            <table>
                {table}
            </table>
        </body>
    </html>
    */

    var base64 =function(s) 
                { 
                    return window.btoa(unescape(encodeURIComponent(s))) 
                }               
    var format =function(s, c) 
                {
                    return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) 
                }

  return function(table, name) 
  {
    if (!table.nodeType) 
        table = document.getElementById(table)

    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}

    window.location.href = uri + base64(format(template, ctx))
  }
}
)()

And nooo this is not workin

<x:ExcelWorkbook>
   <x:Name>
     {anyName}
   </x:Name>
</x:ExcelWorkbook>

Hopefully anybody knows how to do that :) Or does anybody have another code where i can just tell the code something like, elementID from HTML and a filename and maybe the outputpath ?

By the way, it works right know, but the filename seems to be random signs (like "AedyU1TE.xls.part.xls") and always in the user/temp..

Would be nice ;) peace Adi

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.