0

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.Can give me some suggestions library control this? Like this: image excel file

When i try using alasql to set width column,i recieve this bug.How can fix this?:bug when using alasql lib

John
  • 207
  • 2
  • 5
  • 15
  • The second answer here might help: http://stackoverflow.com/questions/21680768/export-to-xls-using-angularjs Do you people even google? – Nick.Mc Oct 27 '16 at 05:40
  • @Nick.McDermaid I updated my question and attach picture. Have you suggestion to fix this or some library lib? – John Oct 27 '16 at 08:57
  • I don't know how to fix that alasql bug sorry. It's just a messagebox though. – Nick.Mc Oct 27 '16 at 12:31

1 Answers1

0

You can create your excel with custom templates using javascript.Have a look on this 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');
};
PraveenG
  • 35
  • 1
  • 7
  • Thanks sir.I updated my question. If I want to wordwrap one column, so how can do that? Have any library to support this? – John Oct 27 '16 at 09:01