使用OLEDB导入Excel时没有引入折叠组

本文关键字:折叠 OLEDB 导入 Excel 使用 | 更新日期: 2023-09-27 17:50:31

我创建了一个程序,从大约75个电子表格中挖掘和导入数据到一个oracle表中。我能够连接,遍历表,并抓取单元格和行,看起来很好。问题是,如果excel表保存与分组行折叠,它跳过行。我找不到任何地方,如果有一个扩展的属性或注册设置,允许我可能展开组上的条目?不知道如何绕过一个折叠的组(不是合并的单元格,那些我可以处理没有问题)。

码位:

//Starting where I iterate through a particular sheet
var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; data source={0};    Extended Properties='"Excel 12.0;HDR=NO;IMEX=1;ReadOnly=0'"", fileName);
OleDbConnection objConn = new OleDbConnection(connectionString);
try
{   
objConn.Open();
System.Data.DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
if (dt != null)
{
    foreach (DataRow row in dt.Rows)
    {
        var adapter = new OleDbDataAdapter("SELECT F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12 FROM [" + row["TABLE_NAME"].ToString() + "]", connectionString);
        var ds = new DataSet();
        try
        {
            adapter.Fill(ds, "anyname");
        }
        catch
        {
            break;
        }
        DataTable data = ds.Tables[0];
        int rownum = 0; 
        // <a bunch of variable declarations>
        foreach (DataRow row_b in data.Rows)
        {
            // start slogging through the rows
            rownum = rownum++;
            // <reset some variables>
            if (rownum == 1) // Catch valid scripts that contain a number
            {
                foreach (DataColumn column in data.Columns)
                {
                    if (column.ToString() == "F1")
                    {
                    // <processing code for this column>
                    }
                    if (column.ToString() == "F2")
                    {
                    //  <processing code for this column>
                    }
                    if (column.ToString() == "F3")
                    {
                    //  <you get the picture>
                    }
                }
        }
            if (rownum == 3)
            {
                // <moving along through the rows...different processing>
            }
                // <..rows 4-11..>
            if (rownum > 12 )
            {
                // <more value assignment>
            }
            string allvals = APPLICATION + E_USER + STEP_DESC + VARIATIONS + STATUS + STOPS_TESTING + ISSUE_NUM + ISSUE_COMMENTS + ADDITIONAL_INFO;
            allvals = allvals.Trim();
            //Don't want sheets that come across as Print Area this shouldn't affect the row processing 
            isPrintArea = 0;
            if (BOOKSHEET.Contains("Print_Area"))
            {
                isPrintArea = 1;
            }
            Boolean addornot=false;
            if (cb_forallscripts.Checked == true) 
            {
                addornot = (STEP_NUM != 0 &&
                allvals != "" &&
                isPrintArea == 0 &&
                SCRIPT_NUM != 0);
            }
            else
            {
                addornot = (STEP_NUM != 0 &&
                allvals != "" &&
                isPrintArea == 0 &&
                SCRIPT_NUM != 0 &&
                runScripts.Contains(SCRIPT_NUM.ToString()));
            }
            if (addornot)
            {
                //<connect to our Oracle db, I set up oCmd outside this> 
                OracleCommand oCmd = new OracleCommand();
                oCmd.Connection = oConn;
                oCmd.CommandType = CommandType.Text;
                oCmd.Parameters.Add("STEP_NUM", STEP_NUM);
                // <... bunch of parameters ...>
                oCmd.Parameters.Add("script", SCRIPT);
                oCmd.CommandText = "<My insert statement> ";
                oCmd.ExecuteNonQuery();
               }
            }
        }
    }
}
catch ( <error processing>)
{ }

使用OLEDB导入Excel时没有引入折叠组

行。OutlineLevel应该是您正在寻找的VBA属性。它可以被读取或设置。请参阅这一页,了解微软相当简洁的描述。的范围内。正如它所说,ClearOutline将清除指定范围的大纲,如下所示。