How to control Excel column size in Javascript?

爷,独闯天下 提交于 2020-01-06 21:41:12

问题


I have a function in Javascript that Exports data to a new Excel file. I'm using ActiveXObejct("Excel.Application") to work with Excel. After The Export of the data is done and I see the result, the data overflows the width of the columns. This is causing some of the data look cut in the table. For example if I have the data '1234567890' in a cell I would see '123456' or '######' in the cell. So how can I control the width of the columns to fit the data they contain? This is a code example of what I'm generally doing:

var Excel = new ActiveXObject("Excel.Application");
var Sheet = new ActiveXObject("Excel.Sheet");
for (var i = 0 ; i < DataArray.length ; i++)
    Sheet.ActiveSheet.Cells(i+1,1).value = DataArray[i];
Excel.visible = true;

回答1:


After the loop:

Sheet.Cells(,1).EntireColumn.ColumnWidth = 20

will change the width of column A.




回答2:


I've managed to find an answer.

Sheet.ActiveSheet.Cells('A:A').ColumnWidth=11;

This will change the width of the first cloumn.



来源:https://stackoverflow.com/questions/23975873/how-to-control-excel-column-size-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!