hide Excel tab from Javascript code

爷,独闯天下 提交于 2020-01-21 09:43:39

问题


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 ?


回答1:


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;

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 ?

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.



来源:https://stackoverflow.com/questions/23499524/hide-excel-tab-from-javascript-code

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