首页 \ 问答 \ 用于Excel工作簿的OleDb方案不显示模式中的行(OleDb scheme for excel workbook not showing rows in schema)

用于Excel工作簿的OleDb方案不显示模式中的行(OleDb scheme for excel workbook not showing rows in schema)

我正在尝试打开Excel工作簿并从工作表中读取。 很简单。

            string sConnction = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"C:\\Users\\sstowe\\Documents\\Ranorex\\RanorexStudio Projects\\BottomLineII\\BottomLineII\\Widget.xls\";Extended Properties=\"Excel 12.0;HDR=NO\";";
        string sSql = "Select * FROM Corporate";

        OleDbConnection cn = new OleDbConnection(sConnction);
        OleDbCommand command = new OleDbCommand(sSql, cn);
        cn.Open();
        // var reader = command.ExecuteReader();

        // Get all Sheets in Excel File
        var dtSheet = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

你看到var reader在我检查时被注释掉了。 我收到一个错误“Microsoft Office Access数据库引擎找不到对象”Corporate“,其中Corporate是表单的名称,Gee说我是否在名称或其他方面犯了错误?因此我打开了dtSheet以查看。在调试器中,dtSheet报告0行,但cn报告的是State of Open。​​因此工作簿正在被找到。有人可以建议如何找到工作表吗?

谢谢。

小号


I am trying to open an Excel workbook and read from a sheet. Pretty simple.

            string sConnction = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"C:\\Users\\sstowe\\Documents\\Ranorex\\RanorexStudio Projects\\BottomLineII\\BottomLineII\\Widget.xls\";Extended Properties=\"Excel 12.0;HDR=NO\";";
        string sSql = "Select * FROM Corporate";

        OleDbConnection cn = new OleDbConnection(sConnction);
        OleDbCommand command = new OleDbCommand(sSql, cn);
        cn.Open();
        // var reader = command.ExecuteReader();

        // Get all Sheets in Excel File
        var dtSheet = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

You see var reader... commented out as I examine. I received an error "The Microsoft Office Access database engine could not find the object 'Corporate'. where Corporate is the name of the sheet. Gee says I, did I make a mistake with the name or something? So I opened dtSheet to look. In the debugger, dtSheet is reporting 0 rows yet cn is reporting State of Open. So the workbook is being found. Can someone advise as to how to find the sheet?

Thank you.

S


原文:https://stackoverflow.com/questions/50913637
更新时间:2023-09-05 08:09

最满意答案

发生什么事

跑完后:

prePickNumbers(four, 4, 40, 20, 1);

... four.myArraysCombined的值是:

[[[2, 17, 20, 1], [7, 2, 20, 11], [7, 14, 3, 16], [12, 17, 3, 8]]]

换句话说,这不是你声称它的结果。 在继续之前,您应该验证您是否具有您认为在流程的每个步骤中执行的结果。 就目前而言,您没有扁平阵列。 您需要先修复它,然后继续迭代和求和。

为什么会这样

最终结构的原因从prePickNumbers中的以下行开始:

tempMyArraysCombined.push(objName.myArray[x]);

您每次都将数组推入另一个数组,因此循环后的结果是数组数组。 但是,然后,您将该结果推送到另一个数组:

objName.myArraysCombined.push(tempMyArraysCombined);

所以最终的结果实际上是一个包含数组数组的数组(注意上面输出中额外的括号组)。 问题是你在整个过程中的每个步骤都将整个数组推送到输出中,这会产生嵌套的混乱。 你应该推动每个数组的元素 ,而不是数组本身。

如何解决它

这是一个可能的解决方案。 用以下函数替换prePickNumbers

function prePickNumbers(objName, theNum, theSumNum, theMaxNum, theMinNum) {
    var tempMyArraysCombined = [];
    for (var x = 0; x < theNum; x += 1) {
        pickNumbers(objName.myArray[x], theNum, theSumNum, theMaxNum, theMinNum);
        for (var j = 0; j < objName.myArray[x].length; j++) {
            objName.myArraysCombined.push(objName.myArray[x][j]);
        }
    }
}

What is happening

After running:

prePickNumbers(four, 4, 40, 20, 1);

...the value of four.myArraysCombined is:

[[[2, 17, 20, 1], [7, 2, 20, 11], [7, 14, 3, 16], [12, 17, 3, 8]]]

In other words, it is not the result that you claim it is. You should verify that you have the result that you think you do at each step of the process, before moving on. As it stands, you do not have a flattened array. You need to fix that first and then move on to iterating and summing.

Why this is happening

The reason for the final structure starts at the following line in prePickNumbers:

tempMyArraysCombined.push(objName.myArray[x]);

You're pushing an array into another array each time, so the result after the loop is an array of arrays. But, then, you push that result into another array:

objName.myArraysCombined.push(tempMyArraysCombined);

So the final result is actually an array containing an array of arrays (notice the extra set of brackets in the output above). The problem is that you're pushing an entire array into your output at each step in the process, which is creating a nested mess. You should be pushing elements of each array, not the arrays themselves.

How to fix it

Here is one possible solution. Replace prePickNumbers with the following function:

function prePickNumbers(objName, theNum, theSumNum, theMaxNum, theMinNum) {
    var tempMyArraysCombined = [];
    for (var x = 0; x < theNum; x += 1) {
        pickNumbers(objName.myArray[x], theNum, theSumNum, theMaxNum, theMinNum);
        for (var j = 0; j < objName.myArray[x].length; j++) {
            objName.myArraysCombined.push(objName.myArray[x][j]);
        }
    }
}

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)