I try to copy styles and set them in a different range.
If try to only one cell, it works, but not if used for multiple cells.
- Code: Select all
CellRange[] ranges1 = worksheet.FindAllString("~FindText~", false, false);
CellStyle cellStyle = worksheet[ranges1[0].Row, ranges1[0].Column].Style;
worksheet[ranges1[0].Row+1 , ranges1[0].Column].Style = cellStyle;
this code is no problem.
but, below codes are some problem
1.
- Code: Select all
CellRange[] ranges1 = worksheet.FindAllString("~FindText~", false, false);
CellStyle cellStyle = worksheet[ranges1[0].Row, ranges1[0].Column , ranges1[0].Row, worksheet.LastColumn].Style;
worksheet[ranges1[0].Row + 1, ranges1[0].Column, ranges1[0].Row + 1, worksheet.LastColumn].Style = cellStyle; // -> exception System.NullReferenceException
2.
- Code: Select all
CellRange[] ranges1 = worksheet.FindAllString("~FindText~", false, false);
CellStyle cellStyle = worksheet[ranges1[0].Row, ranges1[0].Column , ranges1[0].Row, worksheet.LastColumn].Style;
CellStyle tempStyle = worksheet[ranges1[0].Row + 1, ranges1[0].Column, ranges1[0].Row + 1, worksheet.LastColumn].Style;
tempStyle = cellStyle;
// No error occurs, but nothing works.
3.
- Code: Select all
CellRange[] ranges1 = worksheet.FindAllString("~FindText~", false, false);
CellStyle cellStyle = worksheet[ranges1[0].Row, ranges1[0].Column , ranges1[0].Row, worksheet.LastColumn].Style;
CellStyle tempStyle = worksheet[ranges1[0].Row + 1, ranges1[0].Column, ranges1[0].Row + 1, worksheet.LastColumn].Style = cellStyle.clone();
// Exception sprῆ: 'Font size is out of range.'.
I want to copy the style of the row.
Both CopyRow and Copy don't work either.
I want to copy only the style.
but, It copies the data, even if it gives an option.
- Code: Select all
worksheet.CopyRow(worksheet[ranges1[0].Row, worksheet.LastColumn], worksheet, ranges1[0].Row + 1, CopyRangeOptions.CopyStyles) ;
- Code: Select all
CellRange aaa = worksheet[ranges1[0].Row, ranges1[0].Column, ranges1[0].Row, worksheet.LastColumn];
CellRange bbb = worksheet[ranges1[0].Row+1, ranges1[0].Column, ranges1[0].Row+1, worksheet.LastColumn];
worksheet.Copy(aaa, bbb,CopyRangeOptions.CopyStyles );
Is there a way to copy the style of the row, not one cell?