如何在Excel中查找隐藏的图表名称

如何在C#中使用ADO(OLEDB)找出隐藏的Excel表名?

在我的Excel工作簿中有很多工作表。 只有一个Excel工作表处于隐藏模式。 我需要找出隐藏床单的名称。 我的代码find隐藏和可见的工作表。

这是我的代码来查找所有工作表的Excel表名。 是否有可能/任何人可以告诉我如何find隐藏的Excel表名称,而不使用C#中的Interop服务?

connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFile + ";Extended Properties=\"Excel 12.0;;IMEX=1;HDR=YES\""; query = String.Format("SELECT * FROM [{0}", fileName + "]"); OleDbCommand objCmd = new OleDbCommand(query, objCon); OleDbDataAdapter adap = new OleDbDataAdapter(objCmd); adap.FillSchema(dtExcelSchema, SchemaType.Mapped); adap.Fill(dsExecelData); 

如果表格名称以下划线(_)结尾,则隐藏。 常规图表名称将以美元符号($)结尾。

这篇文章适合我

 using Excel = Microsoft.Office.Interop.Excel; ... Excel.Application xlAppSource = null; Excel.Workbook xlWorkBookSource = null; // workbook xlWorkBookSource = xlAppSource.Workbooks.Open(xlsFilePath, 0, false, 5, null, null, false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, null, true, false, 0, true, false, false); // here is your list List<int> list = getHiddenSheetsIndexes(xlWorkBookSource.Worksheets); ... private List<int> getHiddenSheetsIndexes(Excel.Sheets sheets) { // return List<int> indexes = new List<int>(); int index = 0; foreach (Excel.Worksheet sheet in sheets) { index++; if (sheet.Visible == Microsoft.Office.Interop.Excel.XlSheetVisibility.xlSheetHidden) indexes.Add(index); } // return return indexes; }