Method CopySheetFrom
- Namespace
- DocWright.Spreadsheet
- Assembly
- DocWright.Spreadsheet.dll
CopySheetFrom(XlsxDocumentSheet, string?)
Copies a sheet of another workbook to the end of this one.
public XlsxDocumentSheet CopySheetFrom(XlsxDocumentSheet sheet, string? name = null)
Parameters
sheetXlsxDocumentSheetThe sheet. One of this workbook is copied as CopyTo(int, string?) copies it.
namestringThe copy's name; null for the sheet's own name, or when this workbook has a sheet of that name, the name and
(2)as Excel makes it.
Returns
- XlsxDocumentSheet
The copy.
Remarks
What comes. The sheet's cells, with the changes waiting on it; its drawing, charts and pictures; its comments; its tables; its pivot tables, each with the cache it reads, which this workbook then lists; its print settings. Text comes into this workbook's own table of strings. Each cell format used comes into this workbook's style part as the record it was, and a record this workbook already has is used where it stands.
Names. The defined names that belong to the sheet come with it. A name of the other workbook that the sheet uses, or that refers to the sheet, comes too; when this workbook already has a name spelled so, it comes as a name that belongs to the copy, which is what Excel does. A table whose name is taken gets another.
What differs from Excel, and why. Excel, copying a sheet between two open
workbooks, turns each reference to another sheet of the source into a link to the
source file. A workbook held as bytes has no file to link to. Here such a reference
means the sheet of that name in this workbook when there is one, and is
#REF! when there is none; the references lost that way are reported as one
diagnostic. A reference the source made to a third workbook is #REF! as well.
Themes. As in Excel, a colour or a font that names the theme goes on naming it, so in the copy it is this workbook's theme colour and font. A sheet that must look the same in a workbook with another theme has to use colours of its own.
Not carried. A cell format's named style (it becomes Normal with the same look); the people behind threaded comments; the code behind a sheet of a macro workbook. When one workbook counts dates from 1900 and the other from 1904 the numbers are copied as they are and so are other days: a diagnostic says so.
Exceptions
- ArgumentNullException
sheetis null.- ArgumentException
nameis not a legal sheet name, or a sheet of this workbook has it.- InvalidOperationException
The sheet was deleted from its workbook.
- UnsupportedFeatureException
The sheet is not a worksheet or a chart sheet; one workbook is a Strict Open XML one and the other is not; or the sheet has a slicer, a timeline or a table fed by a query, none of which is copied.
- InvalidDocumentException
A part of either workbook is malformed.