Method CopyTo
- Namespace
- DocWright.Spreadsheet
- Assembly
- DocWright.Spreadsheet.dll
CopyTo(int, string?)
Copies the sheet within its workbook.
public XlsxDocumentSheet CopyTo(int index, string? name = null)
Parameters
indexintThe zero-based place in Sheets the copy is to have, from 0 to the number of sheets.
namestringThe copy's name; null for the name Excel gives one: the sheet's name and
(2), or the first number after it that is free, cut to fit 31 characters.
Returns
- XlsxDocumentSheet
The copy. It is an ordinary sheet at once.
Remarks
The copy is the sheet and everything that belongs to it, each with a part of its own: its cells and formats, its drawing, charts and pictures' places, its comments, its tables (under new names, as a workbook cannot have two tables of one name), its pivot tables (which go on using the pivot cache the originals use), its print settings. Changes made to the sheet and not yet saved are in the copy.
Measured against Excel: a formula of the copy that names the sheet copied names
the copy, as do its chart series; a reference through several sheets that starts or
ends on the sheet copied becomes #REF!; everything else is as it was, a
hyperlink's target included. Each defined name that belongs to the sheet is repeated
for the copy, and each name of the workbook that refers to the sheet gets a twin that
belongs to the copy and refers to it. A hidden sheet's copy is hidden. The sheet the
workbook opens on does not change.
Exceptions
- ArgumentOutOfRangeException
indexis not a place in the list.- ArgumentException
nameis not a legal sheet name, or another sheet has it.- InvalidOperationException
The sheet was deleted.
- UnsupportedFeatureException
The sheet has a slicer, a timeline or a table fed by a query, which are not copied.
- InvalidDocumentException
A part of the workbook is malformed.