I'm trying to copy a range of cells with a mix of values and formulas. The cells are also formatted. In excel, the following copies the cells in the range, then pastes them (using PasteSpecial) back over the same range. This keeps all formatting in place, only replacing the formulas with the values.
ActiveSheet.Range(Cells(1, 1), Cells(ActiveCell.row, 255)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
Application.CutCopyMode = False
A couple questions regarding aspose.cells. First, is this even possible? My first try was:
Dim range1 As Range = wsSheet.Cells.CreateRange(0, 0, wsSheet.Cells.MaxDataRow, 254)
As you can see, I created a range, then tried to use CopyValue to copy the values back over the same range. When I open the workbook, there are no changes at all - the sheet still has all formulas and formatting. So is the problem trying to copy a range over itself? Assuming I can get that to work, will CopyValues remove all the formatting?
I'm simply trying to flatten the entire worksheet, so the formatting remains but all formulas are replaced with the values. I'm guessing I can loop over every cell in the range and replace the formulas with the value, but some of the sheets are very large, so hopefully one of the existing methods will do what I need.
Ultimately I'll probably be copying a worksheet from one workbook to another, so if there is a way to do this (keep formatting but convert formulas to values) using one of the worksheet copy methods that would also work.