Skip to main content
deleted 23 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Is there any room to optimize this class (code) Reading from an Excel sheet

Reading theI have created a class for reading data from an Excel sheet and holding on the variable in C# and I have created the class that read from Excel but I. I am not sure Ifif my code is optimized, meaning I will be reading heavyheavily from excelExcel.

Is there a room to further optimized this code more?, I I will be using this class heavyheaving in my code, and thoughtI wanted to get some opinionopinions/feedback -.

I will be calling something like this...:

ExcelReader xl = new ExcelReader();
string sss = xl.ExcelOpenSpreadsheets("mysheet");
//etc...

public class ExcelReader  
{             
    Application _excelApp;
    
    public ExcelReader()
    {
        _excelApp = new Application();
    }
    
    public string ExcelOpenSpreadsheets(string sheetName)
    {
        string _txt = string.Empty;
        try
        {
            Workbook workBook = _excelApp.Workbooks.Open("filename_here",....);
            _txt = ExcelScanIntenal(workBook, sheetName);
        }
        
        catch
        {
            //
            // Deal with exceptions.
            //
        }
        return _txt;
    }
    
    private string ExcelScanIntenal(Workbook workBookIn, string sheetName)
    {
        Worksheet sheet = workBookIn.Sheets[sheetName] as Worksheet;
        
        Range a1 = sheet.get_Range("A1", "B2");
        if (a1 != null)
        {
            string formattedText = r.Text;                   
        }
        
        return formattedText; 
    }

Is there any room to optimize this class (code)

Reading the data from Excel sheet and holding on the variable in C# and I have created the class that read from Excel but I am not sure If my code is optimized meaning I will be reading heavy from excel

Is there a room to optimized this code more?, I will be using this class heavy in my code and thought get some opinion/feedback -

I will be calling something like this...:

ExcelReader xl = new ExcelReader();
string sss = xl.ExcelOpenSpreadsheets("mysheet");
//etc...

public class ExcelReader  
{             
    Application _excelApp;
    
    public ExcelReader()
    {
        _excelApp = new Application();
    }
    
    public string ExcelOpenSpreadsheets(string sheetName)
    {
        string _txt = string.Empty;
        try
        {
            Workbook workBook = _excelApp.Workbooks.Open("filename_here",....);
            _txt = ExcelScanIntenal(workBook, sheetName);
        }
        
        catch
        {
            //
            // Deal with exceptions.
            //
        }
        return _txt;
    }
    
    private string ExcelScanIntenal(Workbook workBookIn, string sheetName)
    {
        Worksheet sheet = workBookIn.Sheets[sheetName] as Worksheet;
        
        Range a1 = sheet.get_Range("A1", "B2");
        if (a1 != null)
        {
            string formattedText = r.Text;                   
        }
        
        return formattedText; 
    }

Reading from an Excel sheet

I have created a class for reading data from an Excel sheet and holding on the variable. I am not sure if my code is optimized, meaning I will be reading heavily from Excel.

Is there a room to further optimized this code? I will be using this class heaving in my code, and I wanted to get some opinions/feedback.

I will be calling something like this:

ExcelReader xl = new ExcelReader();
string sss = xl.ExcelOpenSpreadsheets("mysheet");
//etc...

public class ExcelReader  
{             
    Application _excelApp;
    
    public ExcelReader()
    {
        _excelApp = new Application();
    }
    
    public string ExcelOpenSpreadsheets(string sheetName)
    {
        string _txt = string.Empty;
        try
        {
            Workbook workBook = _excelApp.Workbooks.Open("filename_here",....);
            _txt = ExcelScanIntenal(workBook, sheetName);
        }
        
        catch
        {
            //
            // Deal with exceptions.
            //
        }
        return _txt;
    }
    
    private string ExcelScanIntenal(Workbook workBookIn, string sheetName)
    {
        Worksheet sheet = workBookIn.Sheets[sheetName] as Worksheet;
        
        Range a1 = sheet.get_Range("A1", "B2");
        if (a1 != null)
        {
            string formattedText = r.Text;                   
        }
        
        return formattedText; 
    }
Tweeted twitter.com/#!/StackCodeReview/status/236295187431817217
fixed formatting
Source Link
mseancole
  • 6.2k
  • 1
  • 16
  • 27

Reading the data from Excel sheet and holding on the variable in C# and I have created the class that read from Excel but I am not sure If my code is optimized meaning I will be reading heavy from excel

Is there a room to optimized this code more?, I will be using this class heavy in my code and thought get some opinion/feedback -

I will be calling something like this...:

ExcelReader xl = new ExcelReader();
string sss = xl.ExcelOpenSpreadsheets("mysheet");
//..etc...
//......

 public class ExcelReader  
{             
    Application _excelApp;
    
    public ExcelReader()
    {
        _excelApp = new Application();
    }
    
    public string ExcelOpenSpreadsheets(string sheetName)
    {
        string _txt = string.Empty;
        try
        {
            Workbook workBook = _excelApp.Workbooks.Open("filename_here",....);
            _txt = ExcelScanIntenal(workBook, sheetName);
        }
        
        catch
        {
            //
            // Deal with exceptions.
            //
        }
        return _txt;
    }
    
    private string ExcelScanIntenal(Workbook workBookIn, string sheetName)
    {
        Worksheet sheet = workBookIn.Sheets[sheetName] as Worksheet;
        
        Range a1 = sheet.get_Range("A1", "B2");
        if (a1 != null)
        {
            string formattedText = r.Text;                   
        }
        
        return formattedText; 
    }

Reading the data from Excel sheet and holding on the variable in C# and I have created the class that read from Excel but I am not sure If my code is optimized meaning I will be reading heavy from excel

Is there a room to optimized this code more?, I will be using this class heavy in my code and thought get some opinion/feedback -

I will be calling something like this...:

ExcelReader xl = new ExcelReader();
string sss = xl.ExcelOpenSpreadsheets("mysheet");
//.....
//......

 public class ExcelReader  
{             
    Application _excelApp;
    
    public ExcelReader()
    {
        _excelApp = new Application();
    }
    
    public string ExcelOpenSpreadsheets(string sheetName)
    {
        string _txt = string.Empty;
        try
        {
            Workbook workBook = _excelApp.Workbooks.Open("filename_here",....);
            _txt = ExcelScanIntenal(workBook, sheetName);
        }
        
        catch
        {
            //
            // Deal with exceptions.
            //
        }
        return _txt;
    }
    
    private string ExcelScanIntenal(Workbook workBookIn, string sheetName)
    {
        Worksheet sheet = workBookIn.Sheets[sheetName] as Worksheet;
        
        Range a1 = sheet.get_Range("A1", "B2");
        if (a1 != null)
        {
            string formattedText = r.Text;                   
        }
        
        return formattedText; 
    }

Reading the data from Excel sheet and holding on the variable in C# and I have created the class that read from Excel but I am not sure If my code is optimized meaning I will be reading heavy from excel

Is there a room to optimized this code more?, I will be using this class heavy in my code and thought get some opinion/feedback -

I will be calling something like this...:

ExcelReader xl = new ExcelReader();
string sss = xl.ExcelOpenSpreadsheets("mysheet");
//etc...

public class ExcelReader  
{             
    Application _excelApp;
    
    public ExcelReader()
    {
        _excelApp = new Application();
    }
    
    public string ExcelOpenSpreadsheets(string sheetName)
    {
        string _txt = string.Empty;
        try
        {
            Workbook workBook = _excelApp.Workbooks.Open("filename_here",....);
            _txt = ExcelScanIntenal(workBook, sheetName);
        }
        
        catch
        {
            //
            // Deal with exceptions.
            //
        }
        return _txt;
    }
    
    private string ExcelScanIntenal(Workbook workBookIn, string sheetName)
    {
        Worksheet sheet = workBookIn.Sheets[sheetName] as Worksheet;
        
        Range a1 = sheet.get_Range("A1", "B2");
        if (a1 != null)
        {
            string formattedText = r.Text;                   
        }
        
        return formattedText; 
    }

Reading the data from Excel sheet and holding on the variable in C# and I have created the class that read from Excel but I am not sure If my code is optimized meaning I will be reading heavy from excel

Is there a room to optimized this code more?, I will be using this class heavy in my code and thought get some opinion/feedback -

I will be calling something like this...:

     ExcelReader xl = new ExcelReader();
     string sss = xl.ExcelOpenSpreadsheets("mysheet");
     //.....
     //......

 
     

public class ExcelReader  
    {             
        Application _excelApp;
 
     
    public ExcelReader()
        {
            _excelApp = new Application();
        }
 
     
    public string ExcelOpenSpreadsheets(string sheetName)
        {
            string _txt = string.Empty;
            try
            {
                Workbook workBook = _excelApp.Workbooks.Open("filename_here",....);
                _txt = ExcelScanIntenal(workBook, sheetName);
            }
           
            catch
            {
                //
                // Deal with exceptions.
                //
            }
            return _txt;
        }
 
     
    private string ExcelScanIntenal(Workbook workBookIn, string sheetName)
        {
            Worksheet sheet = workBookIn.Sheets[sheetName] as Worksheet;
 
         
        Range a1 = sheet.get_Range("A1", "B2");
            if (a1 != null)
            {
              string formattedText = r.Text;                   
        }
    }

     
        return formattedText; 
        }

Reading the data from Excel sheet and holding on the variable in C# and I have created the class that read from Excel but I am not sure If my code is optimized meaning I will be reading heavy from excel

Is there a room to optimized this code more?, I will be using this class heavy in my code and thought get some opinion/feedback -

I will be calling something like this...:

     ExcelReader xl = new ExcelReader();
     string sss = xl.ExcelOpenSpreadsheets("mysheet");
     .....
     ......

 
    public class ExcelReader  
    {             
        Application _excelApp;
 
        public ExcelReader()
        {
            _excelApp = new Application();
        }
 
        public string ExcelOpenSpreadsheets(string sheetName)
        {
            string _txt = string.Empty;
            try
            {
                Workbook workBook = _excelApp.Workbooks.Open("filename_here",....);
                _txt = ExcelScanIntenal(workBook, sheetName);
            }
           
            catch
            {
                //
                // Deal with exceptions.
                //
            }
            return _txt;
        }
 
        private string ExcelScanIntenal(Workbook workBookIn, string sheetName)
        {
            Worksheet sheet = workBookIn.Sheets[sheetName] as Worksheet;
 
            Range a1 = sheet.get_Range("A1", "B2");
            if (a1 != null)
            {
              string formattedText = r.Text;                   
            }

            return formattedText; 
        }

Reading the data from Excel sheet and holding on the variable in C# and I have created the class that read from Excel but I am not sure If my code is optimized meaning I will be reading heavy from excel

Is there a room to optimized this code more?, I will be using this class heavy in my code and thought get some opinion/feedback -

I will be calling something like this...:

ExcelReader xl = new ExcelReader();
string sss = xl.ExcelOpenSpreadsheets("mysheet");
//.....
//......
 

public class ExcelReader  
{             
    Application _excelApp;
     
    public ExcelReader()
    {
        _excelApp = new Application();
    }
     
    public string ExcelOpenSpreadsheets(string sheetName)
    {
        string _txt = string.Empty;
        try
        {
            Workbook workBook = _excelApp.Workbooks.Open("filename_here",....);
            _txt = ExcelScanIntenal(workBook, sheetName);
        }
        
        catch
        {
            //
            // Deal with exceptions.
            //
        }
        return _txt;
    }
     
    private string ExcelScanIntenal(Workbook workBookIn, string sheetName)
    {
        Worksheet sheet = workBookIn.Sheets[sheetName] as Worksheet;
         
        Range a1 = sheet.get_Range("A1", "B2");
        if (a1 != null)
        {
            string formattedText = r.Text;                   
        }
         
        return formattedText; 
    }
edited tags
Link
Jeff Vanzella
  • 4.3k
  • 2
  • 24
  • 33
Loading
Source Link
Nick Kahn
  • 259
  • 1
  • 2
  • 7
Loading