在不使用分隔符的情况下逐列读取excel值。 [英] read excel values column by column without using a seperator.

查看:112
本文介绍了在不使用分隔符的情况下逐列读取excel值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码可以根据像;这样的特定选项从excel中读取,所以我必须只使用一列来插入excel中的值,当有很多值时会让人感到困惑。

我需要程序从excel逐行读取而不需要分隔。



这里是代码:

I have a code that reads from excel based on a specific seperative like ";", so I have to insert the values in excel using only one column which is confusing when having many values.
I need the program to read line by line from excel without the need for the seperative.

here is the code :

private static double ProductA(string sentence)
        {
            string strA = sentence.Substring(sentence.LastIndexOf(";") + 1);
            double result = Convert.ToDouble(strA);
            return result;
        }

        private static double ProductB(string sentence)
        {
            string strNewSentense = sentence.Substring(sentence.IndexOf(";") + 1);
            string strB = strNewSentense.Substring(0, strNewSentense.IndexOf(";"));
            double result = Convert.ToDouble(strB);
            return result;
        }

        private static String GetIndex(string sentence)
        {
            string strId = sentence.Substring(0, sentence.IndexOf(";"));
            String result = Convert.ToString(strId);
            return result;
        }

推荐答案

这个问题很不清楚,代码示例看起来毫无意义。但是......



Excel文件不是文本文件;细胞之间没有线,也没有分隔符。如果这是.xlsx文件,则它基于Microsoft Open XML标准,并且文件是ZIP压缩的。请参阅: http://en.wikipedia.org/wiki/Office_Open_XML [ ^ ]。



您可以阅读Excel文档例如,使用Open XML SDK。请参阅我以前的回答:

http://www.codeproject.com/答案/ 587548 / Howplustoplusaddplusmicrosoftplusexcelplus15-0plus#answer1 [ ^ ]。







参见对此答案的评论下面,由Maciej。如果你真的在一个单元格中存储了一些值并想要提取它,我会称之为技术的大量滥用。无论如何,要提取一些由某些字符分隔的字符串,您只需要: http://msdn.microsoft.com/en-us/library/system.string.split%28v=vs.110%29.aspx [ ^ ]。



-SA
The question is quite unclear, and the code sample looks pointless. But…

Excel file is not a text file; there are no "lines" and no "separators" between cells. If this is an .xlsx file, it is based on Microsoft Open XML standard, and the files are ZIP-compressed. Please see: http://en.wikipedia.org/wiki/Office_Open_XML[^].

You can read Excel documents using, for example, Open XML SDK. Please see my past answer:
http://www.codeproject.com/Answers/587548/Howplustoplusaddplusmicrosoftplusexcelplus15-0plus#answer1[^].



See also the comment to this answer below, by Maciej. If you really store some values in a single cell and want to extract the, I would call it a big misuse of technology. Anyway, to extract some string delimited by some characters, all you need is this: http://msdn.microsoft.com/en-us/library/system.string.split%28v=vs.110%29.aspx[^].

—SA


如果谢尔盖是对的(我错了),我建议你使用 SearchBox [ ^ ]。有大量示例如何读取分隔文件,即使您将其称为Excel文件。
If Sergey is right (and i'm wrong), i suggest you to use SearchBox[^]. There are tons of examples how to read delimited files, even if you call them "Excel" file.


这篇关于在不使用分隔符的情况下逐列读取excel值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆