用于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
最满意答案
发生什么事
跑完后:
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]); } } }
相关问答
更多-
这个实际计算可以用2行代码完成,不需要循环: http://codepad.viper-7.com/ieSkHQ $arr1 = array('amount1' => 1, 'amount2' => 6); $arr2 = array('amount1' => 2, 'amount2' => 7); $add = function($a, $b) { return $a + $b; }; $summedArray = array_map($add, $arr1, $arr2); print_r($summe ...
-
如何将多个列与grep组合在一起并对r中的值进行求和(how to combine multiple columns with grep and sum the values in r)[2021-10-14]
这是一个选项,从列的names中提取有关单词,并使用tapply来获得sum 。 str_extract_all返回一个list ('lst')。 用'GENERAL'替换长度为零的元素,然后,使用按功能分组的tapply , unlist数据集,并使用分组变量,即复制'lst'和'df1' row得到sum library(stringr) lst <- str_extract_all(toupper(sub("(pipe)\\.", "\\1", names(df1))), "ENG ... -
这是你可以编写的一个函数, function sum(data, value){ return data.reduce( function(a, b){ return a + b[value]; }, 0); }; var data = [{ startDate: '', endDate: '', value: 33}, { startDate: '', endDate: '', value: 97}, { startDate: '', endDate: ' ...
-
试图对两个数组的值求和(Trying to sum values of two arrays)[2022-07-10]
$a0是$4的另一个名称。 所以你试图同时使用相同的寄存器来处理多个事件( arrayA当前元素的地址,以及几个系统调用的参数),这显然不起作用。 我建议您使用不同的寄存器来保存arrayA的地址。 并且还要始终使用传统的寄存器名称( $v0 , $a1 , $t2等)来避免这些错误。 您还错误地使用系统调用1: la $a0, sum 系统调用1期望打印的值放在$a0 ,但是您将值的地址放在$a0 。 而不是你应该在这里使用lw 。 当然, sum变量是不必要的,因为你可以直接将$t0和$t1加到$a0 ... -
如何组合多个数组(How to combine multiple arrays)[2022-11-28]
干得好: $colors['Colors_All'] = array("Black","Charcoal","Light_Gray","Silver","White","Gold","Bronze","Copper","Platinum","Navy","Royal_Blue","Dodger_Blue","Deep_Sky_Blue","Turquoise","Tiffany_Blue"); $colors['Colors_Bright_All'] = array("Silver","Whi ... -
您需要找出计划插入的值对数,然后生成相应的数字。 这是一个基本的例子( 请不要使用这个,因为这会让你容易受到SQL注入 ): $firstname = array( '1' => john, '2' => mike, '3' => pete ); $lastname = array( '1' => smith, '2' => jones, '3' => ross ); $query = ' INSERT INTO database_table ...
-
由多个数组合并和分组(Merge and group by several arrays)[2023-03-17]
一种可能的方式 $rtn = array(); foreach ($array1 as $key=>$val) { $rtn[$key]+=$val; } foreach ($array2 as $key=>$val) { $rtn[$key]+=$val; } foreach ($array2 as $key=>$val) { $rtn[$key]+=$val; } 以上将把filename, SUM(val)作为关联数组分配到$rtn one possible way $rtn = a ... -
发生什么事 跑完后: prePickNumbers(four, 4, 40, 20, 1); ... four.myArraysCombined的值是: [[[2, 17, 20, 1], [7, 2, 20, 11], [7, 14, 3, 16], [12, 17, 3, 8]]] 换句话说,这不是你声称它的结果。 在继续之前,您应该验证您是否具有您认为在流程的每个步骤中执行的结果。 就目前而言,您没有扁平阵列。 您需要先修复它,然后继续迭代和求和。 为什么会这样 最终结构的原因从prePickNu ...
-
使用javascript(或jquery)添加多个数组的值(Adding values of multiple arrays with javascript (or jquery))[2022-05-25]
而不是改变你的代码,你可以shim forEach。 这是来自MDN的代码,它几乎是“官方”版本: if (!Array.prototype.forEach) { Array.prototype.forEach = function(fun /*, thisArg */) { "use strict"; if (this === void 0 || this === null) throw new TypeError(); var t = Object(thi ... -
MongoDB基于每个元素对来自多个文档的数组求和(MongoDB sum arrays from multiple documents on a per-element basis)[2023-08-04]
如果你有3.2或更新的MongoDb,你可以使用includeArrayIndex 。 然后你应该改变$unwind 。 你的代码应该是这样的: .aggregate( [ { "$unwind" : { path: "$result", includeArrayIndex: "arrayIndex" } }, { "$group": { "_id": "$arrayIndex", "res ...