Aspose.Cells Error with Worksheet.Cells.CopyRow


#1

I have a new error working with Version 4.0.2.6 and 4.0.2.0
It works just fine using version 3.7.1.0

This happens in both single threaded and multi-threaded execution.
Here is the line of code I am executing

workSheet.Cells.CopyRow(workSheetTemplate.Cells, 8, 35);

The usually execption this is thrown is "ArgumentOutOfRangeException"

Error: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Data: System.Collections.ListDictionaryInternal
Target: System.Object get_Item(Int32)
Stack: at System.Collections.ArrayList.get_Item(Int32 index)
at Aspose.Cells.Style.GetStyle(Worksheets sheets, Int32 xfIndexRead)
at Aspose.Cells.Cell.get_Style()
at Aspose.Cells.Cells.CopyRow(Cells sourceCells, Int32 sourceRowIndex, Int32 destinationRowIndex)
at ICE.Net.Reporting.ExcelWorkItem.ProcessBreakLevelDetail(SmartTags stSmartTag) in C:\Documents and Settings\prjdo000\My Documents\Visual Studio 2005\Projects\IC_Report\IC_Report\ExcelWorkItem.cs:line 646


#2

Here is a code sample and an attachment.

using System;
using System.Collections.Generic;
using System.Text;
using Aspose.Cells;

namespace AsposeCopyError
{
class Program
{
static void Main(string[] args)
{
Workbook excelWorkbook1 = new Workbook();
Workbook excelWorkbook2 = new Workbook();
excelWorkbook1.Open(@"C:\Template.xlt");
Worksheet wsTemplate = excelWorkbook1.Worksheets[0];
Worksheet wsFinal = excelWorkbook2.Worksheets[0];
wsFinal.Copy(wsTemplate);
wsFinal.Cells.CopyRow(wsTemplate.Cells, 7, 20);
wsFinal.Cells.CopyRow(wsTemplate.Cells, 8, 21);

excelWorkbook2.Save(@"C:\Final.xls", FileFormatType.Default);

}
}


#3

Hi,

Thanks for considering Aspose.Cells.

Well, I executed the following simple code with Aspose.Cells 4.0.2.0, 4.0.2.3 and 4.0.2.6 and the result is perfect related to CopyRow() method of Worksheet class:

Workbook workBookTemplate = new Workbook();

workBookTemplate.Open(@"d:\book1.xls");

Worksheet workSheetTemplate = workBookTemplate.Worksheets[0];

Workbook workBook = new Workbook();

workBook.Worksheets.Clear();

int index = workBook.Worksheets.Add();

Worksheet workSheet = workBook.Worksheets[index];

workSheet.Cells.CopyRow (workSheetTemplate.Cells, 8, 35);

workBook.Save(@"d:\testcopyrow.xls");

Could you please post your sample source code and template file here.

Regards

Amjad Sahi

Aspsoe Nanjing Team


#4

I just did it about 5 minutes earlier.

I think it may have to do with the fact that I have resized the height of the row I am trying to copy.

This worked on 3.7.1.0


#5

Hi,

Well, you may use AutoFitColumns() method before using CopyRow() method, so you may change your code like this:

Workbook excelWorkbook1 = new Workbook();

Workbook excelWorkbook2 = new Workbook();

excelWorkbook1.Open(@"c:\Template.xlt");

Worksheet wsTemplate = excelWorkbook1.Worksheets[0];

Worksheet wsFinal = excelWorkbook2.Worksheets[0];

wsFinal.Copy(wsTemplate);

wsFinal.AutoFitColumns();

wsFinal.Cells.CopyRow(wsTemplate.Cells, 7, 20);

wsFinal.Cells.CopyRow(wsTemplate.Cells, 8, 21);

excelWorkbook2.Save(@"d:\Final.xls", FileFormatType.Default);

Regards

Amjad Sahi

Aspose Nanjing Team


#6

But I do not want to AutoFitColumns my worksheet. I already have them set to the size I desire. Why should I have to run this command just to save a workbook. Can this bug be corrected?


#7

Please try v4.0.2.7 attached at http://www.aspose.com/Community/forums/thread/56866.aspx. It’s fixed.