I need to copy a workbook from one workbook to another and I'm stuck a bit. The basis is that I have a "master" workbook that stores templates for multiple reports and then I have to make a blank copy of a specific worksheet and add it to a new workbook.
This is what I have done so far:
Private Zero CreateNewWorkbook (Tables Table) {Excel.Application app = null; Excel.Workbook book = null; Excel.Worksheet Sheet = Faucet; Try {string startPath = System.IO.Path.GetDirectoryName (System.Digagnostics.Process.GetCurrentProcess (). MainModule.FileName); String filePath = System.IO.Path.Combine (startup, "sal1011forms.xls"); Microsoft.Win32.SaveFileDialog sfd = New Microsoft.Win32.SaveFileDialog (); App = new Excel.Application (); Book = app. Works. Open (filepath); Sheet = (Excel worksheet) book. Worksheets.gate_item ((int table) 1); Sfd.AddExtension = True; Sfd.FileName = table.ToString () + ".xls"; Sfd.InitialDirectory = Environmental GETFolderPath (Environment.SpecialFolder.MyDocuments); If (sfd.ShowDialog () == true) {sheet.SaveAs (sfd.FileName); }} Finally {if (book! = Null) {book.Close (); } If (app! = Null) {app.Quit (); } This.ReleaseObject (sheet); This.ReleaseObject (book); This.ReleaseObject (app); }}
There is only one problem at this time that when I call. Save to worksheet () () () () ()), it saves all worksheets from the original workbook in a new workbook.
Thank you in advance,
Listened to
You can send sheet.copy () You can also use the method.
Actually, sheets. Copy copies the copy, and will automatically create a new workbook at the same time.
After getting your code to get the worksheets, try adding the following code. Get_Item:
// copies the sheet and copy into a new workbook sheet. Copy (type messing, type.); // new workbook sheet = app. Sets sheet variables in sheet copied to workbook [2]. Sheets [1];
There is also a reference to the copy () function:
Comments
Post a Comment