Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Export to excel using aspose
Message
De
09/03/2011 10:40:28
 
 
À
09/03/2011 10:38:01
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01502896
Message ID:
01503035
Vues:
24
>>>>Do you know off hand is it possible to read in part of a datatable. So I could set the start point in the data import and the number of rows I want
>>>
>>>I see there's a Cells.ImportDataRow() method but I'd imagine calling that repeatedly might be slow. You could, I suppose, create a temporary table to pass to the ImportDataTable(). Ugly but would work:
       public DataTable GetPartTable(DataTable dt, int start, int rowCount)
>>>        {
>>>            int stop = start + rowCount;
>>>            DataTable CloneTable = dt.Clone();
>>>            for (int i = start ; i< stop ; i++)
>>>            {
>>>                CloneTable.ImportRow(dt.Rows[i]);
>>>            }
>>>            return CloneTable;
>>>        }
Then:
DataTable tmp = GetPartTable(OriginalTable, 0, 65656);
(Needs some parameter checking.....)
>>
>>Do you think using a DataReader be better ?
>
>I honestly don't know. If you were cloning the whole table then:
CloneTable.Load(dt.CreateDataReader());
might be quicker but where you have to loop to import a fixed number of rows I'm not sure. You could make the above a bit neater by:
     IEnumerable<DataTable> GetBlock(DataTable dt, int blockSize)
>        {
>            int i = 0;
>            for (; i < dt.Rows.Count - blockSize; i += blockSize)
>            {
>                yield return GetPartTable(dt, i, blockSize);
>            }
>            yield return GetPartTable(dt, i, dt.Rows.Count - i);
>        }
then:
foreach (DataTable dt in GetBlock(OriginalTable, 65536))
>            {  Cells.Add(.....);  }
But my count calculation might need verifying :-{
And it would always be worth checking that the full table size is > 64K before using this approach....
(Duh. Updated to myself....)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform