如何在Javascript中控制Excel列大小? [英] How to control Excel column size in Javascript?

查看:120
本文介绍了如何在Javascript中控制Excel列大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Javascript函数,可将数据导出到新的Excel文件。我正在使用ActiveXObejct( Excel.Application)与Excel配合使用。在完成数据导出并看到结果之后,数据溢出了列的宽度。这导致表中的某些数据看起来被剪切。例如,如果我在一个单元格中有数据 1234567890,我会在该单元格中看到 123456或 ######。那么,如何控制列的宽度以适合它们包含的数据呢?
这是我通常在做什么的代码示例:

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;


推荐答案

循环后:

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

将更改A列的宽度。

这篇关于如何在Javascript中控制Excel列大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆