使用javascript生成Excel文件 [英] Generate Excel file using javascript

查看:111
本文介绍了使用javascript生成Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



最好的问候,

解决方案

点击此处使用电子表格文档我们可以使用javascript
动态创建电子表格,只需按照文档并添加语法
您可以参考这个

 '<?xml version =1.0?>',
'< Workbook xmlns =urn:schemas-microsoft-com:office:spreadsheet xmlns:o =urn:schemas-microsoft-com:office:officexmlns:x =urn:schemas-microsoft-com:office:excelxmlns:ss =urn:schemas-microsoft-com:office: xmlns:html =http://www.w3.org/TR/REC-html40>',
'< DocumentProperties xmlns =urn:schemas-microsoft-com:office:办公室>< Title>'+ theTitle +'< / Title>< / DocumentProperties>',
'< OfficeDocumentSettings xmlns =urn:schemas-microsoft-com:office:office>  
'< WindowHeight>',
' + worksheet.height +'< / WindowHeight>',
'< WindowWidth>'+ worksheet.width +'< / WindowWidth>',
'< ProtectStructure> False< / ProtectStructure> ',
'< ProtectWindows> False< / ProtectWindows>',
'< / ExcelWorkbook>',

'< Styles>',

'< Style ss:ID =Defaultss:Name =Normal>',
'<对齐ss:Vertical =Bottom/>',
' <边框/>',
'<字体ss:FontName =Calibrix: Family =Swissss:Size =12ss:Color =#000000/>',
'< Interior />',
'< NumberFormat /> ,
'< Protection />',
'< / Style>',

'< Style ss:ID =title>',
'< Borders />',
'< Font ss:Bold =1ss:Size =18/>',
'<对齐ss: =Centerss:Vertical =Centerss:WrapText =1/>',
'< NumberFormat ss:Format =@/>',
' / Style>',

'< Style ss:ID =headercell>',
'< Font ss:Bold =1ss:Size =10 />',
'<对齐ss:水平=中心ss:WrapText =1/>',
'<内部ss:颜色=#A3C9F1 Pattern =Solid/>',
'< / Style>',


'< Style ss:ID =even>',
'< Interior ss:Color =#CCFFFFss:Pattern =Solid/>',
'< / Style>',


'< ;样式ss:ID =evendatess:Parent =even>',
'< NumberFormat ss:Format =yyyy-mm-dd/>',
' ; / Style>',


'< Style ss:ID =evenintss:Parent =even>',
'< Numberformat ss: Format =0/>',
'< / Style>',

'< Style ss:ID =evenfloatss:Parent =even> ',
'< Numberformat ss:Format =0.00/>',
'< / Style>',

'< Style ss: odd>',
'< Interior ss:Color =#CCCCFFss:Pattern =Solid/>',
'< / Style>',

'< Style ss:ID =groupSeparator>',
'< Interior ss:Color =#D3D3D3ss:Pattern =Solid/>',
'< / Style>',

'<样式ss:ID =odddatess:Parent =odd>',
'< NumberFormat ss:Format = yyyy-mm-dd/>',
'< / Style>',

'<样式ss:ID =oddintss: >',
'< NumberFormat Format =0/>',
'< / Style>',

'< Style ss: oddfloatss:Parent =odd>',
'< NumberFormat Format =0.00/>',
'< / Style>


'< / Styles>
workheet.xml,
'< / Workbook>'

和atlast编码上面的xml到base64并形成一个数据网址,从'datata:application / vnd.ms-excel; base64,{base64 encoded above xml}开始



看这样请点击这里下载excel 在这里输入代码


Is there any simple way to generate an simple excel file using JavaScript?

Best Regards,

解决方案

Click Here Using spread sheet documentation We can dynamically create spreadsheet using javascript just follow documentation and add syntax You refer this

'<?xml version="1.0"?>',
            '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">',
            '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Title>' + theTitle + '</Title></DocumentProperties>',
            '<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"><AllowPNG/></OfficeDocumentSettings>',
            '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">',
            '<WindowHeight>' + worksheet.height + '</WindowHeight>',
            '<WindowWidth>' + worksheet.width + '</WindowWidth>',
            '<ProtectStructure>False</ProtectStructure>',
            '<ProtectWindows>False</ProtectWindows>',
            '</ExcelWorkbook>',

            '<Styles>',

            '<Style ss:ID="Default" ss:Name="Normal">',
            '<Alignment ss:Vertical="Bottom"/>',
            '<Borders/>',
            '<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="12" ss:Color="#000000"/>',
            '<Interior/>',
            '<NumberFormat/>',
            '<Protection/>',
            '</Style>',

            '<Style ss:ID="title">',
            '<Borders />',
            '<Font ss:Bold="1" ss:Size="18" />',
            '<Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1" />',
            '<NumberFormat ss:Format="@" />',
            '</Style>',

            '<Style ss:ID="headercell">',
            '<Font ss:Bold="1" ss:Size="10" />',
            '<Alignment ss:Horizontal="Center" ss:WrapText="1" />',
            '<Interior ss:Color="#A3C9F1" ss:Pattern="Solid" />',
            '</Style>',


            '<Style ss:ID="even">',
            '<Interior ss:Color="#CCFFFF" ss:Pattern="Solid" />',
            '</Style>',


            '<Style ss:ID="evendate" ss:Parent="even">',
            '<NumberFormat ss:Format="yyyy-mm-dd" />',
            '</Style>',


            '<Style ss:ID="evenint" ss:Parent="even">',
            '<Numberformat ss:Format="0" />',
            '</Style>',

            '<Style ss:ID="evenfloat" ss:Parent="even">',
            '<Numberformat ss:Format="0.00" />',
            '</Style>',

            '<Style ss:ID="odd">',
            '<Interior ss:Color="#CCCCFF" ss:Pattern="Solid" />',
            '</Style>',

            '<Style ss:ID="groupSeparator">',
            '<Interior ss:Color="#D3D3D3" ss:Pattern="Solid" />',
            '</Style>',

            '<Style ss:ID="odddate" ss:Parent="odd">',
            '<NumberFormat ss:Format="yyyy-mm-dd" />',
            '</Style>',

            '<Style ss:ID="oddint" ss:Parent="odd">',
            '<NumberFormat Format="0" />',
            '</Style>',

            '<Style ss:ID="oddfloat" ss:Parent="odd">',
            '<NumberFormat Format="0.00" />',
            '</Style>


            '</Styles>
            worksheet.xml,
            '</Workbook>'

And atlast encode above xml to base64 and form a data-url start with'data:application/vnd.ms-excel;base64,{base64 encoded above xml}

Atlast it may look like this Please click here to download excel enter code here

这篇关于使用javascript生成Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆