diana onea

diana onea

  • NA
  • 8
  • 17.1k

C# Import Excel - XlWBATemplate.XlWBATWorksheet Error

Jun 20 2011 11:42 AM
Hello, 

I am trying to create a new Excel file with a blank sheet.
My code is the following : 

using Excel = Microsoft.Office.Interop.Excel;

public void format()
{
List<string> sheets = getSheetName(path);

Excel._Application xlsAppNew = new Excel.Application();
xlsAppNew.Visible = true;

foreach (string s in sheets)
{

if (s.Contains("A,B") == true)
{
char[] delim = { 'A' };

string[] grupa = s.Split(delim, 4);

listView1.Items.Add(grupa[0] + "A");
Excel.Workbook workbook = Excel.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Excel.Sheets newSheet = workbook.Worksheets;


listView1.Items.Add(grupa[0] + "B");
//save in another sheet

}
else
listView1.Items.Add(s.ToString());
//save in another sheet
}
}


But I get the following error : The name 'XlWBATemplate' does not exist in the current context.
What`s missing? 

Please help. 

Answers (2)