office-js - 如何使用office.js api删除Excel中表格的边框

标签 office-js office-2016

我已经使用 Office api 创建了一个表格,并且我不想在其上有任何样式。默认情况下,当使用 Office api 创建表格时,我看到应用了默认表格样式,我只想要纯数据。

解决这个问题 1.我尝试使用某种颜色更改边框颜色和范围填充区域,使其看起来没有任何样式。

我有两个问题要问。 1. 如何删除使用office.js api创建的excel表格的默认样式 2.如果第一个不可能,那么如何给范围没有边框,

我尝试使用发际线和细边框,如 https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/rangeborder.md 中所述。

但看起来发际线不起作用,发际线和细线给出相同的边框

        Excel.run(function (ctx) { 
        var sheetName = "Sheet1";
        var rangeAddress = "A1:F8";
        var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeAddress);
  range.format.borders.getItem('InsideHorizontal').weight = "Hairline";
                range.format.borders.getItem('InsideVertical').weight = "Hairline";
                range.format.borders.getItem('EdgeBottom').weight = "Hairline";
                range.format.borders.getItem('EdgeLeft').weight = "Hairline";
                range.format.borders.getItem('EdgeRight').weight = "Hairline";
                range.format.borders.getItem('EdgeTop').weight = "Hairline";

                //range.format.borders.getItem('InsideHorizontal').style = "No Border";
                //range.format.borders.getItem('InsideVertical').style = 'No Border';
                //range.format.borders.getItem('EdgeBottom').style = 'No Border';
                //range.format.borders.getItem('EdgeLeft').style = 'No Border';
                //range.format.borders.getItem('EdgeRight').style = 'No Border';
                //range.format.borders.getItem('EdgeTop').style = 'No Border';

                range.format.borders.getItem('InsideHorizontal').color = 'Gray';
                range.format.borders.getItem('InsideVertical').color = 'Gray';
                range.format.borders.getItem('EdgeBottom').color = 'Gray';
                range.format.borders.getItem('EdgeLeft').color = 'Gray';
                range.format.borders.getItem('EdgeRight').color = 'Gray';
                range.format.borders.getItem('EdgeTop').color = 'Gray';        return ctx.sync(); 
    }).catch(function(error) {
            console.log("Error: " + error);
            if (error instanceof OfficeExtension.Error) {
                console.log("Debug info: " + JSON.stringify(error.debugInfo));
            }
        });

我的代码看起来与此类似。

请指导我如何删除表格边框

最佳答案

您需要将样式设置为“无”而不是“无边框”。

range.format.borders.getItem('InsideHorizontal').style = "None";
range.format.borders.getItem('InsideVertical').style = 'None';
range.format.borders.getItem('EdgeBottom').style = 'None';
range.format.borders.getItem('EdgeLeft').style = 'None';
range.format.borders.getItem('EdgeRight').style = 'None';
range.format.borders.getItem('EdgeTop').style = 'None';

可能的值记录在 RangeBorder object (JavaScript API for Excel)

编辑: 以上仅适用于较新的 Excel API。使用经典表绑定(bind)时,还有一种替代方法。 http://dev.office.com/docs/add-ins/excel/format-tables-in-add-ins-for-excel 提供了此过程的演练。 。

关于office-js - 如何使用office.js api删除Excel中表格的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37666075/

相关文章:

javascript - 如何使用 Excel Javascript Addins 计算所有非空白单元格?

excel - 如何使用 setStartupBehavior API 调用?

ms-access - MS Access 中未定义“FileDialog”类型

javascript - 为 Outlook 2016 创建任务 Pane Office 加载项

c# - 从 WordprocessingDocument 文档中删除 WebExtensionPart 后损坏

excel - 解析 'sandbox' 属性 : 'ms-allow-popups' is an invalid sandbox flag 时出错

javascript - 在不包含 office.js 的情况下检测 Office 插件主机

office-js - Office 2016 加载项与 http ://localhost 通信