Free Support Forum - aspose.com

Problems inserting rows

Hi, please find attached a sample that demonstrates and describes a problem inserting rows. This is using Aspose.Cells 4.1.2.6 on .NET 1.1

If you need any more information, please let me know

Regards

Kai

Hi Kai,

Thanks for the detailed description with excel files

We have checked a bit and noticed some differences with MS Excel, we will figure it soon.

Thank you.

Hi,

Please try this fix.And you should change your codes to set style of Row.

Workbook workbook = new Workbook();
workbook.Open(@"F:\FileTemp\InsertStart.xls");
// precoloured sheet
Worksheet worksheet = workbook.Worksheets[0];

// insert a block
CellArea ca = new CellArea();

ca.StartColumn = 1;
ca.StartRow = 2;
ca.EndColumn = 4;
ca.EndRow = 5;
worksheet.Cells.InsertRange(ca, ShiftType.Down);


// colour the rows
Worksheet worksheet1 = workbook.Worksheets[1];


for (int i = 4; i < 25; i++)
{
Style style = worksheet1.Cells.Rows[i].Style;
style.ForegroundColor = System.Drawing.Color.Yellow;
style.Pattern = BackgroundType.Solid;

StyleFlag styleFlag = new StyleFlag();
styleFlag.CellShading = true;
worksheet1.Cells.Rows[i].ApplyStyle(style, styleFlag);
//worksheet1.Cells.Rows[i].Style.ForegroundColor = System.Drawing.Color.Yellow;
//worksheet1.Cells.Rows[i].Style.Pattern = BackgroundType.Solid;
}

// put some data in a column (which will get shifted when we insert)
for (int i = 0; i < 26; i++)
worksheet1.Cells[i, 2].PutValue("Data in row " + i.ToString());

// add another cell somewhere in the coloured area (Outside the area to shift)
worksheet1.Cells[6, 7].PutValue("Hello world");

// insert a block
CellArea ca1 = new CellArea();

ca1.StartColumn = 2;
ca1.StartRow = 2;
ca1.EndColumn = 4;
ca1.EndRow = 5;
worksheet1.Cells.InsertRange(ca1, ShiftType.Down);

// colour the cells
Worksheet worksheet2 = workbook.Worksheets[2];

for (int i = 4; i < 25; i++)

for (int j = 0; j < 256; j++)
{

worksheet2.Cells[i, j].Style.ForegroundColor = System.Drawing.Color.Yellow;
worksheet2.Cells[i, j].Style.Pattern = BackgroundType.Solid;
}

// put some data in a column (which will get shifted when we insert)
for (int i = 0; i < 26; i++)
worksheet2.Cells[i, 2].PutValue("Data in row " + i.ToString());

// add another cell somewhere in the coloured area (Outside the area to shift)
worksheet2.Cells[6, 7].PutValue("Hello world");

// insert a block
CellArea ca2 = new CellArea();

ca2.StartColumn = 1;
ca2.StartRow = 2;
ca2.EndColumn = 4;
ca2.EndRow = 5;
worksheet2.Cells.InsertRange(ca2, ShiftType.Down);


workbook.Save(@"F:\FileTemp\InsertEnd.xls");

Hi Kai,

Please try this fix.