首页 \ 问答 \ 从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: { ...

相关文章

更多

最新问答

更多
  • 您如何使用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)