Excel Office.js中的单元格/列宽度

时间:2022-05-04 22:19:05

The latest Javascript Api for Excel makes working with worksheets much easier, but I seem to miss the ability of setting a cells width in code. Range objects have a format property, but that only supports font sizes and borders and such.

最新的Javascript Api for Excel使得处理工作表变得更加容易,但我似乎错过了在代码中设置单元格宽度的能力。 Range对象具有format属性,但仅支持字体大小和边框等。

What am i missing? I'm inserting dates into columns from a task pane add-in, but the default cell width means that the user only sees '####' and has to manually resize the cells.. not very nice

我错过了什么?我将日期插入任务窗格加载项的列中,但默认的单元格宽度意味着用户只能看到“####”并且必须手动调整单元格的大小..不是很好

3 个解决方案

#1


3  

you can use Range object to set the width as

您可以使用Range对象将宽度设置为

range.format.columnWidth = 130;

#2


0  

I am glad to know that you like the new JavaScript APIs for Excel. Actually we are releasing a new wave of APIs for Excel which will include the set column width and a lot of other new exciting features including worksheet protections, sort/filter and so much more. Check it out on GitHub.

我很高兴知道你喜欢Excel的新JavaScript API。实际上,我们正在发布一系列用于Excel的新API,其中包括设置列宽和许多其他令人兴奋的新功能,包括工作表保护,排序/过滤等等。在GitHub上查看。

If you want to try out the new APIs, make sure you have the latest Office 2016 for Windows or Office365. Here are the instructions

如果您想试用新的API,请确保您拥有最新的Office 2016 for Windows或Office365。这是说明

  1. With in your add-in, in HTML, replace the existing Office.js script reference with

    在您的加载项中,使用HTML替换现有的Office.js脚本引用

      <script src=" https://appsforoffice.microsoft.com/lib/beta/hosted/office.js" type="text/javascript"></script>
    
  2. If you want IntelliSense for a even more delightful coding experience, go to Scripts/References/_references.js, remove the last two entries, and instead replace them with

    如果您希望IntelliSense获得更加愉快的编码体验,请转到Scripts / References / _references.js,删除最后两个条目,然后将其替换为

/// <reference path=" https://appsforoffice.microsoft.com/lib/beta/hosted/office.js" />
Thanks, Sky

/// 谢谢,天空

Microsoft

#3


0  

I like the autofitColumns function:

我喜欢autofitColumns函数:

range.format.autofitColumns();

The only time I don't like this function is when I have so much data in one cell that it stretches the cell to be wider than the screen, which makes horizontal scrolling miserable. In that case, I go with @shyam_'s answer:

我不喜欢这个功能的唯一一次是当我在一个单元格中有如此多的数据时,它将单元格拉伸到比屏幕更宽,这使得水平滚动变得悲惨。在那种情况下,我选择@ shyam_的回答:

range.format.columnWidth = 130;

#1


3  

you can use Range object to set the width as

您可以使用Range对象将宽度设置为

range.format.columnWidth = 130;

#2


0  

I am glad to know that you like the new JavaScript APIs for Excel. Actually we are releasing a new wave of APIs for Excel which will include the set column width and a lot of other new exciting features including worksheet protections, sort/filter and so much more. Check it out on GitHub.

我很高兴知道你喜欢Excel的新JavaScript API。实际上,我们正在发布一系列用于Excel的新API,其中包括设置列宽和许多其他令人兴奋的新功能,包括工作表保护,排序/过滤等等。在GitHub上查看。

If you want to try out the new APIs, make sure you have the latest Office 2016 for Windows or Office365. Here are the instructions

如果您想试用新的API,请确保您拥有最新的Office 2016 for Windows或Office365。这是说明

  1. With in your add-in, in HTML, replace the existing Office.js script reference with

    在您的加载项中,使用HTML替换现有的Office.js脚本引用

      <script src=" https://appsforoffice.microsoft.com/lib/beta/hosted/office.js" type="text/javascript"></script>
    
  2. If you want IntelliSense for a even more delightful coding experience, go to Scripts/References/_references.js, remove the last two entries, and instead replace them with

    如果您希望IntelliSense获得更加愉快的编码体验,请转到Scripts / References / _references.js,删除最后两个条目,然后将其替换为

/// <reference path=" https://appsforoffice.microsoft.com/lib/beta/hosted/office.js" />
Thanks, Sky

/// 谢谢,天空

Microsoft

#3


0  

I like the autofitColumns function:

我喜欢autofitColumns函数:

range.format.autofitColumns();

The only time I don't like this function is when I have so much data in one cell that it stretches the cell to be wider than the screen, which makes horizontal scrolling miserable. In that case, I go with @shyam_'s answer:

我不喜欢这个功能的唯一一次是当我在一个单元格中有如此多的数据时,它将单元格拉伸到比屏幕更宽,这使得水平滚动变得悲惨。在那种情况下,我选择@ shyam_的回答:

range.format.columnWidth = 130;