We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Repeating tabular data in Excel using Aspose

Can we repeat tabular data easily in excel using aspose? I am attaching a sample of the output that we want…

  • All the data in a unique color is coming from database OR if not directly we can handle the same in DotNet.
  • Different color shows the repeatations that we want.
  • Number of times the section to repeat will vary as it depends on the input. So it can vary from 1 to 100 also in few cases.

As we are using Aspose for our regular reports which show simple data in row/column format, we are thinking to use aspose here as well. Is this easily achievable in Dot Net?

Any help/samples/code in this context is highly appreciated…!!


Hi,


Thank you for contacting Aspose support.

If you requirement is to repeat the data with formatting then most convenient solution is to use the Range.Copy method to copy a range of cell on multiple locations. Please check the following piece of code and its resultant spreadsheet (attached). Please notice how data is being repeated on second worksheet.

C#

var book = new Workbook(dir + “Report (1).xlsx”);
var sSheet = book.Worksheets[0];
var source = sSheet.Cells.CreateRange(“A1:F25”);
var dSheet = book.Worksheets[book.Worksheets.Add()];
int rowSize = 0;
for (int i = 0; i < 5; i++)
{
var destination = dSheet.Cells.CreateRange(rowSize, 0, source.RowCount, source.ColumnCount);
destination.Copy(source, new PasteOptions() { PasteType = PasteType.All});
rowSize = dSheet.Cells.MaxDataRow + 3;
}
book.Save(dir + “output.xlsx”);