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

3
  • The second answer here might help: stackoverflow.com/questions/21680768/… Do you people even google? Commented Oct 27, 2016 at 5:40
  • @Nick.McDermaid I updated my question and attach picture. Have you suggestion to fix this or some library lib? Commented Oct 27, 2016 at 8:57
  • I don't know how to fix that alasql bug sorry. It's just a messagebox though. Commented Oct 27, 2016 at 12:31

1 Answer 1

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');
};
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks sir.I updated my question. If I want to wordwrap one column, so how can do that? Have any library to support this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.