"how to copy data from one excel file to another excel file using visual studio c#" Code Answer's
You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "how to copy data from one excel file to another excel file using visual studio c#" answered properly. Developers are finding an appropriate answer about how to copy data from one excel file to another excel file using visual studio c# related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like how to copy data from one excel file to another excel file using visual studio c#. Enter your desired code related query in the search bar and get every piece of information about C# code related question on how to copy data from one excel file to another excel file using visual studio c#.
how to copy data from one excel file to another excel file using visual studio c#
//using Spire.Xls;
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
Workbook curWorkBook = null;
Workbook destWorkbook = null;
Worksheet workSheet = null;
Worksheet newWorksheet = null;
Object defaultArg = Type.Missing;
try
{
// Copy the source sheet
curWorkBook = app.Workbooks.Open("D:\\Book1.xlsx", defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg);
workSheet = (Worksheet)curWorkBook.Sheets[1];
workSheet.UsedRange.Copy(defaultArg);
// Paste on destination sheet
destWorkbook = app.Workbooks.Open("D:\\Book2.xlsx", defaultArg, false, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg, defaultArg);
newWorksheet = (Worksheet)destWorkbook.Worksheets.Add(defaultArg, defaultArg, defaultArg, defaultArg);
newWorksheet.UsedRange._PasteSpecial(XlPasteType.xlPasteValues, XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false);
}
catch (Exception exc)
{
//.Windows.Forms.MessageBox.Show(exc.Message);
}
finally
{
if (curWorkBook != null)
{
curWorkBook.Save();
curWorkBook.Close(defaultArg, defaultArg, defaultArg);
}
if (destWorkbook != null)
{
destWorkbook.Save();
destWorkbook.Close(defaultArg, defaultArg, defaultArg);
}
}
app.Quit();
}
}
}
Source: social.msdn.microsoft.com
All those coders who are working on the C# based application and are stuck on how to copy data from one excel file to another excel file using visual studio c# can get a collection of related answers to their query. Programmers need to enter their query on how to copy data from one excel file to another excel file using visual studio c# related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to copy data from one excel file to another excel file using visual studio c# for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of how to copy data from one excel file to another excel file using visual studio c# while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "how to copy data from one excel file to another excel file using visual studio c#". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to copy data from one excel file to another excel file using visual studio c# resolved professionally and stay updated to the latest C# updates.