从Javascript代码隐藏Excel选项卡 [英] hide Excel tab from Javascript code

查看:216
本文介绍了从Javascript代码隐藏Excel选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过Javascript以编程方式隐藏Excel选项卡。
ExcelSheetName.Visible = False似乎不起作用。我已经google了很多但还没有收到正确的解决方案。如何做?

How can I hide an Excel tab programmatically through Javascript. ExcelSheetName.Visible=False doesn't seem to work. I've googled a lot but yet not received the right solution. How to do that ?

推荐答案

要隐藏Excel表单,请设置 Visible 属性对应的工作表对象到 0 false
例如,如果您有一个具有两张名为 Sheet1 Sheet2 的Excel文件,以下代码将使用 Sheet1 hidden:

To hide an Excel sheet, set the Visible property of the corresponding Worksheet object to 0 or false. For example, if you have an Excel file with two sheets named Sheet1 and Sheet2, the following code will open this file with the Sheet1 hidden:

var objExcel = new ActiveXObject("Excel.Application");
objExcel.Visible = true;
objExcel.Workbooks.Open("C:\\Book1.xlsx");

objExcel.ActiveWorkbook.Sheets("Sheet1").Visible = false;
// You can aslo use this --
//objExcel.ActiveWorkbook.Sheets("Sheet1").Visible = 0; // xlSheetHidden



所以我说你指出。这是我的代码:

So I said as u pointed out. This is my code:

var fso = new ActiveXObject("Scripting.FileSystemObject");
var xl = new ActiveXObject("Excel.Application");
xl.Visible = true;
var wb = xl.Workbooks.Open(fso.GetAbsolutePathName("Temp.csv"));
xl.ActiveWorkbook.Sheets("Temp").Visible = false;

但是,这样做,我将错误设置为无法设置Worksheet类的Visible属性。任何线索可能是可能的错误?

But on doing so, I get the error as Unable to set the Visible property of the Worksheet class. Any clue what could be the possible error ?

错误是因为CSV文件在Excel中只有一个选项卡,您不能隐藏唯一可见的选项卡。至少1个选项卡必须始终可见。

The error is because CSV files have only one tab in Excel, and you can't hide the only visible tab. At least 1 tab must always be visible.

这篇关于从Javascript代码隐藏Excel选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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