0

In Excel there is a feature to hide some worksheets. I am reading a document which contains these kind of sheets and I want to ignore them.

This is the place which I can hide, or unhide worksheets:

  1. On the Home tab, in the Cells group, click Format.
  2. Under Visibility, click Hide & Unhide, and then click Unhide Sheet.

How to get list of ONLY Excel VISIBLE worksheet names in Excel using ExcelDataReader?

4

3 回答 3

2

如果使用阅读器界面,则该IExcelDataReader.VisibleState属性返回当前阅读工作表的可见性状态。

如果使用.AsDataSet(),则可以从中获取相同的值DataTable.ExtendedProperties["visiblestate"]

于 2017-11-09T20:43:30.720 回答
1

如何使用 Excel 获取可见工作表名称列表ExcelDataReader

// Prepare your reader by 
var stream = File.Open(yourExcelFilename, FileMode.Open, FileAccess.Read);
var excelDataReader = ExcelDataReader.ExcelReaderFactory.CreateOpenXmlReader(stream);

// This variable will store visible worksheet names
List<string> visibleWorksheetNames;

// Use a loop to read workbook    
visibleWorksheetNames = new List<string>();
for (var i = 0; i < excelDataReader.ResultsCount; i++)
{
    // checking visible state
    if (excelDataReader.VisibleState == "visible")
    {
        visibleWorksheetNames.Add(excelDataReader.Name);
    }

    excelDataReader.NextResult();
}
于 2018-01-08T13:16:42.173 回答
0

只读数据集的可见工作表:

using (var stream = File.Open("test.xlsx", FileMode.Open, FileAccess.Read))
{
    using (var reader = ExcelReaderFactory.CreateReader(stream))
    {
        var ds = reader.AsDataSet(new ExcelDataSetConfiguration()
        {
            FilterSheet = (tableReader, sheetIndex) => tableReader.VisibleState == "visible",
        });
    }
}

于 2021-11-03T04:48:04.793 回答