简体   繁体   English

使用JavaScript API格式化嵌入式excel中的单元格

[英]Format cells in embedded excel using JavaScript API

Is there a JavaScript API to format cells in an embedded excel file ? 是否有JavaScript API可以格式化嵌入式excel文件中的单元格? We are able to format the cells via the EWS DOM API but that seems unstable and browser dependent. 我们可以通过EWS DOM API设置单元格的格式,但这似乎不稳定并且依赖于浏览器。

Yes definitely possible. 是的,绝对有可能。 Here are some examples. 这里有些例子。

function Format1() {
    var tableData = new Office.TableData();
    Office.select("bindings#MyTableXXX").setFormatsAsync(
                [

                //row 1
                { cells: { row: 0, column: 2 }, format: { alignHorizontal: "right", fontSize: 15 } },

                //row 2
                { cells: { row: 1, column: 0 }, format: { numberFormat: "dd-mmm-yy", fontStyle: "bold" } }, 
                { cells: { row: 1, column: 1 }, format: { fontColor: "red", fontStyle: "bold", numberFormat: "#,###.00", borderColor: "blue" } },

                //row 3
                { cells: { row: 2 }, format: { height: 30 } },

                //Whole table: 'Office.Table.All', 'Office.Table.Data' (no headers) and 'Office.Table.Headers'
                { cells: Office.Table.All, format: { borderStyle: "dotted" } },

                ],
        function (asyncResult) {

            //NOW DO OUTPUT OR ERROR
            if (asyncResult.status === "failed") {
                writeToPage('Error Format1: ' + asyncResult.error.message, 3);
            }
            else {
                writeToPage('Table cell formats changed', 1);
            }
        });
}

For more information see www.microsoft-office-add-ins.com 有关更多信息,请参见www.microsoft-office-add-ins.com

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

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