简体   繁体   English

导出前如何格式化Excel文件?

[英]How to format file excel before export?

I want to controll layout this file before exported it.Example: I want fix width column, the title color, the border table or hightline one row or wordwrap by code before export.I using Angularjs in my project.Can give me some suggestions library support this? 我想在导出之前控制该文件的布局示例:我想在导出之前固定宽度列,标题颜色,边框表或高线一行或通过代码自动换行。我在项目中使用Angularjs 。可以给我一些建议库支持这个吗? Like this: Picture file excel 像这样: 图片文件excel

When i try using alasql library to set width column,i recieve this bug. 当我尝试使用alasql库设置width列时,我收到此错误。 Picture Bugs 图片错误

How can fix this? 如何解决呢?

 app.factory('Excel', function ($window) {
var uri = 'data:application/vnd.ms-excel;base64,',
    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>',
    base64 = function (s) { return $window.btoa(unescape(encodeURIComponent(s))); },
    format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) };
return {
    tableToExcel: function (tableId, worksheetName) {
        var table = $(tableId),
            ctx = { worksheet: worksheetName, table: table.html() },
            href = uri + base64(format(template, ctx));
        return href;
    }
};
})

calling function 调用功能

  $scope.exportToExcel = function (tableId) { // ex: '#my-table'          
    var exportHref = Excel.tableToExcel(tableId, 'sheetname');
    $timeout(function () { location.href = exportHref; }, 100); // trigger download
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM