SIVA

SIVA

  • NA
  • 742
  • 707.4k

How to Save the Data into 2nd sheet in Excel file in ASP .Net

Jan 5 2012 9:46 AM
Hi All,
The following code is helped me to save the record in Sheet1 of excel file..
 

ApplicationClass excelApp = new ApplicationClass();

Workbook workbook = (Workbook)excelApp.Workbooks.Add(Missing.Value);

Worksheet worksheet;

string SourcePath = "D:\\Excel\\Emp.xls";

string Path="D:\\Excel\\";

string DestPath = Path +"Emp_"+ txtID.Text + ".xls";

System.IO.File.Copy(SourcePath, DestPath);

workbook = excelApp.Workbooks.Open(DestPath, 0, false, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

worksheet = (Worksheet)workbook.Sheets.get_Item(1);

((Range)worksheet.Cells["5", "C"]).Value2 = txtName.Text;

((Range)worksheet.Cells["6", "C"]).Value2 = txtID.Text;

((Range)worksheet.Cells["7", "C"]).Value2 = txtDesignation.Text;

((Range)worksheet.Cells["8", "C"]).Value2 = txtDept.Text;

((Range)worksheet.Cells["9", "C"]).Value2 = txtDate.Text;

((Range)worksheet.Cells["5", "E"]).Value2 = txtAppraiser.Text;

((Range)worksheet.Cells["6", "E"]).Value2 = txtReviewer.Text;

((Range)worksheet.Cells["7", "E"]).Value2 = txtHeadOfDept.Text;

((Range)worksheet.Cells["8", "E"]).Value2 = txtPreviousProcess.Text;

workbook.Save();

workbook.Close(0, 0, 0);

excelApp.Quit();

 


Now My requirement is i need to save some other in Sheet2 of the same file how can i achieve this

Answers (1)