首页 \ 问答 \ 从C#读取Excel文件(Reading an Excel File From C#)

从C#读取Excel文件(Reading an Excel File From C#)

我有一个连接字符串来读取我的C#项目中的excel文件,看起来像这样..

String ConnectionString  = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                                      "Data Source=" + VariableFile + ";" +
                                      "Extended Properties=Excel 8.0;";

我也有objConn.Open(); 打开文件..

问题是我的程序打开文件的唯一时间是如果我手动打开Excel文件并运行我的程序。 任何人都可以帮助我从我的C#代码打开文件,而不必手动打开它。 我收到错误消息:当我尝试运行它时未找到可安装的ISAM,而无需首先打开Excel文件。

谢谢


I have a connection string to read an excel file from my C# project that looks like this..

String ConnectionString  = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                                      "Data Source=" + VariableFile + ";" +
                                      "Extended Properties=Excel 8.0;";

and I also have objConn.Open(); to open the file..

The problem is the only time my program will open the file is if I open the Excel file manually and run my program. Can anyone help me to open the file from my C# code instead of having to open it first manually. I get the error message: Could not find installable ISAM when I try to run it without opening the Excel file first.

Thank you


原文:https://stackoverflow.com/questions/7246413
更新时间:2022-10-27 14:10

最满意答案

y轴没有限制(除了数字类型的javascript限制外)

但是,您可能看到的可能是9007199254740992以上的精度损失 - 这不是巧合的17位数(请参阅什么是JavaScript的最高整数值,数字可以达到而不会丢失精度?以及相关问题

Chart.js使用值范围来确定如何缩放条形。 它通过从最大值中减去min并使用差值来实现。

现在,如果所有值都相同,Chart.js会添加一个小数字(0.5)来产生差异并继续使用此差异。

如果添加0.5实际产生差异,那么一切都很好 - 但是如果结果高于9007199254740992,它将大部分被精度限制吞噬,给出0差异并弄乱Chart.js的y轴计算。

当数字高于9007199254740992并且它们的差异不够大时会发生同样的问题(它们基本上将相同的数字向上舍入 - >它们被视为一组相等的值 - > 0.5被添加 - >它主要被吞噬了精度限制)

这是一个快速的价值示例,以及为什么它会起作用/不起作用

// works because there is a (small) difference and the numbers are < 9007199254740992
var a = [9007199254740991, 9007199254740992];

// won't work because there is no difference and the numbers are > 9007199254740992 - 0.5
var b = [9007199254740992, 9007199254740992];

// won't work because there is no difference and the numbers are = 9007199254740992 - 0.5
var c = [9007199254740991.5, 9007199254740991.5];

// works because there is no difference and the numbers are < 9007199254740992 - 0.5
var d = [9007199254740991.4, 9007199254740991.4];

// works because there is a significant difference even though the numbers are > 9007199254740992
var e = [12345678901234567890, 12345678901434567891];

// works because there is a significant difference even though the numbers are > 9007199254740992
var f = [0, 12345678901434567891];

// won't work because there is only a small difference and the numbers are > 9007199254740992
var g = [9007199254740992, 9007199254740993];

简而言之,您的条形图不会渲染,因为您有一组相同(或没有显着差异)的值,并且是9007199254740992 - 0.5或更高。

您可以添加一个虚拟值0来强制它渲染(或者可能添加另一个虚拟系列的0值),确保存在显着差异 - 或者如果所有值都在17位数范围内并且非常彼此接近,只绘制偏移量即表示你有1701和1705 ...图1和5并在工具提示中输入170作为值前缀。


There is no limit on the y-axis (except possibly the javascript limit on the number type)

However, what you are possibly seeing might be a LOSS of precision above 9007199254740992 - which not so coincidentally is a 17 digit number (see What is JavaScript's highest integer value that a Number can go to without losing precision? and the associated problems

Chart.js uses the value range to figure out how to scale the bars. It does this by subtracting the min from the max and using the difference.

Now, if all values are same, Chart.js adds a small number (0.5) to make a difference and proceeds with this difference.

All is well and good if adding this 0.5 actually produces a difference - however if the result is above 9007199254740992, it will mostly get swallowed up by the precision limit giving a 0 difference and messing up Chart.js's y axis calculations.

The same issue happens when the numbers are above 9007199254740992 and their difference is not large enough (they basically round up the same number -> they are treated as a set of equal values -> 0.5 is added -> it mostly get swallowed up by the precision limit)

Here's a quick sample of values and why it will work / not work

// works because there is a (small) difference and the numbers are < 9007199254740992
var a = [9007199254740991, 9007199254740992];

// won't work because there is no difference and the numbers are > 9007199254740992 - 0.5
var b = [9007199254740992, 9007199254740992];

// won't work because there is no difference and the numbers are = 9007199254740992 - 0.5
var c = [9007199254740991.5, 9007199254740991.5];

// works because there is no difference and the numbers are < 9007199254740992 - 0.5
var d = [9007199254740991.4, 9007199254740991.4];

// works because there is a significant difference even though the numbers are > 9007199254740992
var e = [12345678901234567890, 12345678901434567891];

// works because there is a significant difference even though the numbers are > 9007199254740992
var f = [0, 12345678901434567891];

// won't work because there is only a small difference and the numbers are > 9007199254740992
var g = [9007199254740992, 9007199254740993];

In short, your bar is not rendering because you have a set of values that are same (or do not significantly differ) AND are 9007199254740992 - 0.5 or above.

You could just add a dummy value of 0 to force it to render (or possibly add another dummy series of 0 values) by making sure there is a significant difference - or if all your values are going to be in the 17 digit range and very close to each other, just plot the offset i.e. say you have 1701 and 1705... plot 1 and 5 and put in the 170 as a value prefix in the tooltip.

相关问答

更多
  • 只需在图表配置中使用labels.margin属性即可。 这是API参考 。 Just use labels.margin property in chart config. Here is API Reference.
  • 使用d3轴的刻度方法。 由于x轴的刻度格式是时间,因此您可以指定计数和刻度格式。 var xAxis = d3.svg.axis().scale(x).orient("bottom").ticks(d3.time.day, 2); var yAxis = d3.svg.axis().scale(y).orient("left").ticks(5); 您可以从此处参考d3 svg轴以及此处的时间格式 Use ticks method of d3 axis. Since tick format of x a ...
  • 我不太清楚你想要输出的样子。 这样的事情会好吗? ggplot(data = data , aes(x = 'COUNTRY', y = count, fill = reorder(country, count)))+ geom_bar(stat = "identity")+ xlab("COUNTRY")+ ylab("TOTAL")+ theme_minimal()+ geom_text(aes(label = sprintf(" ...
  • y轴没有限制(除了数字类型的javascript限制外) 但是,您可能看到的可能是9007199254740992以上的精度损失 - 这不是巧合的17位数(请参阅什么是JavaScript的最高整数值,数字可以达到而不会丢失精度?以及相关问题 Chart.js使用值范围来确定如何缩放条形。 它通过从最大值中减去min并使用差值来实现。 现在,如果所有值都相同,Chart.js会添加一个小数字(0.5)来产生差异并继续使用此差异。 如果添加0.5实际产生差异,那么一切都很好 - 但是如果结果高于9007199 ...
  • 您可以对每个用户使用: d.values.reduce(function(sum, d){ return sum + d.amount; },0) 这是减少文档 .- You can use on each user: d.values.reduce(function(sum, d){ return sum + d.amount; },0) Here's reduce documentation.-
  • 实际上,我认为我找到了一种非常基本和静态的方法来设置宽度。 在chart.js(版本1.0.2)中,第1576行: this.yLabelWidth = (this.display && this.showLabels) ? longestText(this.ctx,this.font,this.yLabels) + 10 : 0; 我只是将其改为静态数字'93'。 this.yLabelWidth = 93; 我肯定会稍微修补一下,我可以调用表格中第一个单元格的宽度,使它们都相同。 Actually, ...
  • “y轴:显示”实际上是针对y轴线本身。 我不认为这与标签本身有关。 我认为echarts正试图将这些标签保留在那里,但他们只是没有显示。 注意:刚下班回家,我原来的答案不起作用。 你在使用网格吗? 我只是测试它,并使用这样的东西: myChart.setOptions({ grid: { left: '15px', right: '15px' }, .........(add more options as needed here) } "y-axis: sho ...
  • NVD3 Javascript库引用他们的网站,“尝试构建可重复使用的图表和图表组件”。 它的创建者做了几个关键决定,以强调图表的可重用性: 他们专注于实施标准图表设计(折线图,条形图,散点图),但以灵活,互动的方式实施。 他们对所有图表使用了相同的数据结构要求: 主数据阵列包含多个数据系列,每个数据系列代表数据的逻辑分组; 每个系列都是包含两个或多个变量的单个数据对象的数组。 所有图形都具有相似的样式并重用重要的代码片段。 NVD3库允许您创建分组条形图或堆积条形图,甚至可以创建两者之间交互式动画的图表 ...
  • 将X轴最小可见值设置为使条形可见的值: renderer.setXAxisMin(-0.5); Set the X axis minimum visible value to something that will make the bar visible: renderer.setXAxisMin(-0.5);
  • 如果要控制图表的高度,可以更改画布的高度 或者如果您想更改y轴值的高度,请尝试以下操作。 下面将确保栏的最大尺寸为25000,每一步为5000,回调将标记为5k,10k,15k,20k,25k var chartConfig = { type: 'bar', data: data, options: { scales: { ...

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的