2016-10-27 103 views
0

我想在導出之前控制佈局此文件。例如:我想通過導出前的代碼修正寬度列,標題顏色,邊框表或hightline一行或wordwrap。可以給我一些建議庫控制這個? 像這樣: image excel file導出excel與自定義佈局

當我嘗試使用alasql設置寬度專欄中,我收到此bug.How可以解決這個問題?:bug when using alasql lib

+0

這裏的第二個答案可能會幫助:http://stackoverflow.com/questions/21680768/export-to-xls-using-angularjs你人甚至谷歌? –

+0

@ Nick.McDermaid我更新了我的問題並附上圖片。你有建議修復這個或一些庫lib? – John

+0

我不知道如何解決alasql bug抱歉。這只是一個消息框。 –

回答

0

您可以使用javascript.Have看看自定義模板創建您的Excel在這個http://jsfiddle.net/kmqz9/223/ <a id="test" href="" onclick="downloadReport();">Test.xls</a>

// Test script to generate a file from JavaScript such that MS Excel will honor non-ASCII characters.. 


testJson = [ 
{ 
    "name": "First Name", 
    "city": "City", 
    "country":" Country of Manas", 
    "birthdate": "Birth Date", 
    "amount": "Paisa Ketey" 
}, 
{ 
    "name": "Tony Peña", 
    "city": "New York", 
    "country": "United States", 
    "birthdate": "1978-03-15", 
    "amount": 42 

}, 
{ 
    "name": "Ζαλώνης Thessaloniki", 
    "city": "Athens", 
    "country": "Greece", 
    "birthdate": "1987-11-23", 
    "amount": 42 
} 
]; 

// Simple type mapping; dates can be hard 
// and I would prefer to simply use `datevalue` 
// ... you could even add the formula in here. 
testTypes = { 
    "name": "String", 
    "city": "String", 
    "country": "String", 
    "birthdate": "String", 
    "amount": "String" 
}; 

emitXmlHeader = function() { 
    return '<?xml version="1.0"?>\n' + 
      '<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">\n' + 
      '<ss:Worksheet ss:Name="Sheet1">\n' + 
      '<ss:Table>\n\n'; 
}; 

emitXmlFooter = function() { 
    return '\n</ss:Table>\n' + 
      '</ss:Worksheet>\n' + 
      '</ss:Workbook>\n'; 
}; 

jsonToSsXml = function (jsonObject) { 
    var row; 
    var col; 
    var xml; 
    var data = typeof jsonObject != "object" 
      ? JSON.parse(jsonObject) 
      : jsonObject; 

    xml = emitXmlHeader(); 

    for (row = 0; row < data.length; row++) { 
     xml += '<ss:Row>\n'; 

     for (col in data[row]) { 
      xml += ' <ss:Cell>\n'; 
      xml += ' <ss:Data ss:Type="' + testTypes[col] + '">'; 
      xml += data[row][col] + '</ss:Data>\n'; 
      xml += ' </ss:Cell>\n'; 
     } 

     xml += '</ss:Row>\n'; 
    } 

    xml += emitXmlFooter(); 
    return xml; 
}; 

console.log(jsonToSsXml(testJson)); 

function download (content, filename, contentType) { 
    if (!contentType) contentType = 'application/octet-stream'; 
    var a = document.getElementById('test'); 
    var blob = new Blob([content], { 
     'type': contentType 
    }); 
    a.href = window.URL.createObjectURL(blob); 
    a.download = filename; 
    window.navigator.msSaveOrOpenBlob(blob,filename); 
}; 

function downloadReport() 
{ 
    download(jsonToSsXml(testJson), 'test.xls',  'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 
}; 
+0

謝謝先生。我更新了我的問題。如果我想用單詞包裝一個專欄,那該怎麼辦?有任何圖書館來支持這個? – John