加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 从电子表格中读取行数据

发布时间:2020-12-15 22:03:43 所属栏目:百科 来源:网络整理
导读:使用 tools SpreadSheetLight我找不到如何读取电子表格文件的行.特别是表1. 我遇到的两个问题是 我无法看到获得行 我无法看到获得列索引 这是我的代码 public void ParseExcelFile(FileInfo file) { using (SLDocument sl = new SLDocument()) { FileStream
使用 tools SpreadSheetLight我找不到如何读取电子表格文件的行.特别是表1.

我遇到的两个问题是

>我无法看到获得行
>我无法看到获得列索引
这是我的代码

public void ParseExcelFile(FileInfo file) 
{
    using (SLDocument sl = new SLDocument())
    {
        FileStream fs = new FileStream(file.FullName,FileMode.Open);

        MemoryStream msFirstPass = new MemoryStream();
        SLDocument sheet1 = new SLDocument(fs,"Sheet1");


        // There is no way that I can see to get the Rows
        foreach(var row in sheet1.Rows)
        {
            foreach(SLCell c in row)
            {
                // There is no way that I can see to get the Column Index
                switch(c.Column )
                {
                    case 1:
                        //Handle data if cell is Column 1
                        break;
                    case 2:
                        //Handle data if cell is Column 2
                        break;
                    case 3:
                        //Handle data if cell is Column 3
                        break;
                }
            }
        }



    }

}//func

解决方法

由于SpreadSheetLight似乎没有公开的代码文档,因此人们很难回答这个问题.基于几个假设,我有两个建议:

> SLDocument.Row.SLCell类是否具有任何索引属性?如果是这样,您可以从那里获得所需的信息.>您可以将forach替换为for来跟踪行和列.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读