Reputation: 1623
I have to name the excell sheets myself with the patient name which i have in the input file. rather than the sheet1 sheet2 etc.
in VBA:
Set wsPatient =ThisWorkbook.Worksheets.Add
wsPatient.Name = "ThePatientName"
Upvotes: 0
Views: 131
Reputation: 613461
Like this:
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp != null)
{
xlApp.Visible = true;
Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet wsPatient = (Worksheet)wb.Worksheets.Add(missing, missing, missing, missing);
wsPatient.Name = "ThePatientName";
}
See this MSDN article for details of the references you need to add and the using
statements.
Once you get past the boiler-plate, the C# code will be pretty much identical to what you are used to with VBA.
Upvotes: 4
Reputation: 1884
I don't think that you can do the same in C# as you did in VBA, VBA (Visual Basic for Applications) provides built in functions to integrate the programming language (VBA) with Excel, However there are lots of libraries that you can use to work with Excel in C#
Upvotes: 2