How to build a ExcelHelper class and use it?

Jul 31, 2014 at 7:41 AM
Hello guys!

I need to build a ExcleHelper class to open an excel, in another class, using the ExcelHelper class to open a excel.
Are the codes following right? Thanks!

public void ExcelHelper(string fileName)
    {
        if (!File.Exists(fileName))
            throw new Exception("The excel file dose not exist!");


        beforeTime = DateTime.Now;
        app = new Excel.ApplicationClass();
        app.Visible = true;
        afterTime = DateTime.Now;


        workBook = app.Workbooks.Open(fileName,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing);


        workSheet = (Excel.Worksheet)workBook.Sheets.get_Item(1);

    }
public void ButtonClick(object sender, EventArgs e)
    {
        var featureSet = ExcelHelper();

        if (featureSet != null)
        { 

            var layer = App.Map.Layers.Add(featureSet);
            layer.LegendText = "Point from Excel";

        }
    }