C锐读Excel文件 [英] C sharp reading excel file

查看:67
本文介绍了C锐读Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel文件,例如,有31条记录.如何在不跳过任何记录的情况下读取每10条记录的文件.

这是我写的代码.

I have an excel file which has for example 31 records. How can i read the file with each 10 record without skip any record.

Here is the code i wrote.

double rows = _RowColObjToList.Count;
               int blocks  = Convert.ToInt32(Math.Ceiling(rows/10));

               int i = 0;
               int slotIndex = 0;
               int maxReq = 10;

               for (int j = 0; j < blocks; j++)
               {
                   slotIndex = 0;
                   for (i = j + i; i < rows; i++)
                   {
                       //slotIndex = i % maxReq;

                       reqRecord[slotIndex] = new liveSMWS.RequestRecord();

                       reqRecord[slotIndex].FullName = _RowColObjToList[i].FullName.fieldValue;
                       reqRecord[slotIndex].Address1 = _RowColObjToList[i].Address.fieldValue;
                       reqRecord[slotIndex].Suite = _RowColObjToList[i].Suite.fieldValue;
                       reqRecord[slotIndex].City = _RowColObjToList[i].City.fieldValue;
                       reqRecord[slotIndex].State = _RowColObjToList[i].State.fieldValue;
                       reqRecord[slotIndex].Zip = _RowColObjToList[i].Zip.fieldValue;

                       if (slotIndex == maxReq-1)
                           break;
                       else
                           ++slotIndex;

                   }
                   reqArray.Record = reqRecord;
                   MessageBox.Show(_RowColObjToList.Count.ToString());
                   //_RowColObjToList = new List<RowColObjLine>();
                   //_RowColObjToList.Count -= maxReq;

                   //rspArray = liveSM.DoSmartMover(reqArray);
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }





在此代码中,每当j = 2时,i就会递增到.例如,如果i = 19j = 2,则i将变为21,并且跳过记录号20.并且,例如,如果i = 29j将是32,它将跳过记录3031.

请帮助...





In this code whenever j = 2, the i will increment to. For example if i = 19 and j = 2, then i will become 21, and it skip record number 20. And, for example, if i = 29 so j will be 32, and it will skip records 30 and 31.

Please help...

推荐答案

测试您的循环并查看结果:
Test your loops and see the results:
for (int j = 0; j < blocks; j++)
    {
        for (i = j + i; i < rows; i++)
        {
            Console.WriteLine("{0} | {1}", j, i);
        }
}



如果我没记错,对于blocks = 30rows = 50,结果将是:



If i''m not wrong, for blocks = 30 and rows = 50 the result will be:

0 | 0
0 | 1
0 | 2
...
0 | 50


这是什么意思?第二个循环仅执行一次!

我无法编译C#代码(我只有Visual Studio和VB),所以我无法对其进行测试.

尝试自己找到解决方案. 提示: 先读取行,然后读取列(块).


如何使其连续循环而不跳过任何记录.


What it''s mean? The second loop will execute only once!

I can not compile C# code (i have Visual Studio with VB only), so i can''t test it.

Try to find solution yourself. Tip: First read rows, then columns (blocks).


how to make it loop continuously without skipping any record.

for (int j = 0; j < blocks; j++)
    {
        for (int i = 0; i < rows; i++)
        {
            Console.WriteLine("{0} | {1}", j, i);
        }
}



[/EDIT]



[/EDIT]


这篇关于C锐读Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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