Forum > FPSpreadsheet
fpspread copyWorksheet and copyRows
kjteng:
What is the correct way to call the above two methods? I tried the following but failed:
a) with wbSrc1.Workbook do
CopyWorksheetFrom(GetWorksheetByIndex(1));
b) with wbSrc1.Workbook do
CopyWorksheetFrom(GetFirstWorksheet);
I get error message: Sheet1 is not a valid worksheet name
c) with wbSrc1 do
Worksheet.CopyRow(1, 2, Workbook.GetWorksheetByName('Sheet3'));
This does not seem to copy any things from sheet3?
wp:
This is the signature of the CopyWorksheet function
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- function CopyWorksheetFrom(AWorksheet: TsWorksheet; ReplaceDuplicateName: Boolean = false): TsWorksheet;You obviously did not use the optional second parameter which - if true - forces the copied worksheet to have a new unique sheetname.
CopyRow copies only a row record, it does not copy any cells visible within that row. The row record contains information on row height and row format (default format assigned to empty cells)
kjteng:
Thanks for the quick reply.
Yes I did not set the ReplaceDuplicateName. Now it works but I am still dont quite understand what is the use of this parameter.When should we (or when can we) set it to False?
wp:
--- Quote from: kjteng on July 09, 2018, 05:32:32 pm ---When should we (or when can we) set it to False?
--- End quote ---
When you copy a worksheet from another workbook and you know that there is no name collision.
I just wonder why I selected the default value to be false, and why there is a default value at all. (...long time gone....)
Please note also that this feature was added by user request, and I guess it's not heavily tested, in particular with regard to the new formula storage and 3d formulas.
kjteng:
Ok, after few round testing, I have a better understand of this method now. The CopyWorkSheet actually does not copy the source worksheet to current worksheet (Self) but instead it append a new worksheet (duplicate of the source worksheet) to the workbook. As both the source and destination worksheet are in the same workbook, we must set ReplaceDuplicateName to true i.e. use a different name for the new worksheet appended.
We can omit the ReplaceDuplicateName (hence default to false)
if the source worksheet is in another workbook and there is no worksheet having the same name in the destination workbook.
Nevertherless, I think the error message 'SheetX is not a valid worksheet name' is misleading. May be 'SheetX already exists' would be better.
Navigation
[0] Message Index
[#] Next page