1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Opening Excel 2003 file by c#

Discussion in 'C#' started by hesham_51, Dec 30, 2008.

  1. hesham_51

    hesham_51 New Member

    Joined:
    Nov 3, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone

    First ,My name is Hashem I'm a beginner in c#, I'm trying to open Excel file(2003) but I get error at Open Function in the below code :


    (Old Format Or Invalid Library Of kinds (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD)):nonod:


    Is there anybody can help me? where I use the following code that i have collected.



    public static Excel.Application ExlApp;
    public static Excel.Workbook ExlWrkBook;
    public static Excel.Worksheet ExlWrkSheet;



    Excel.Application ExcApp = new Excel.Application();
    ExcApp.Visible = true;
    Excel.Workbook excelWorkbook = ExcApp.Workbooks.Open("D:\\Salary Calc.xls", 0, false, 5, "", "", true,Excel.XlPlatform.xlWindows, "\t", true, false, 0, false, true, true);

    Excel.Sheets ExcSheet = excelWorkbook.Worksheets;
    string currentSheet = "Sheet1";
    Excel.Worksheet excelWorksheet = (Excel.Worksheet)ExcSheet.get_Item(currentSheet);
    Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1");

    :confused:
     
  2. neo_vi

    neo_vi New Member

    Joined:
    Feb 1, 2008
    Messages:
    722
    Likes Received:
    15
    Trophy Points:
    0
    Occupation:
    Software engineer
    Location:
    Earth
    Home Page:
    is there any use in opening an EXCEL file in c#. if s wats it!
     
  3. hesham_51

    hesham_51 New Member

    Joined:
    Nov 3, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I need to make a form that can store the specific data to specific cells ,thats it
     
  4. hesham_51

    hesham_51 New Member

    Joined:
    Nov 3, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hi
    Any Help ?
     
  5. neo_vi

    neo_vi New Member

    Joined:
    Feb 1, 2008
    Messages:
    722
    Likes Received:
    15
    Trophy Points:
    0
    Occupation:
    Software engineer
    Location:
    Earth
    Home Page:
  6. hesham_51

    hesham_51 New Member

    Joined:
    Nov 3, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Thanks alot all Mr. Neo_vi

    I got it
     
  7. JosipK

    JosipK New Member

    Joined:
    Dec 17, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello,
    you can try using GemBox.Spreadsheet .NET library. It is much more easier to use than Excel Automation.
    Here is a sample C# code how to export DataSet to Excel:
    Code:
    // Create new ExcelFile.
    var ef = new ExcelFile();
    
    // Imports all the tables from DataSet to new file.
    foreach (DataTable dataTable in dataSet.Tables)
    {
        // Add new worksheet to the file.
        var ws = ef.Worksheets.Add(dataTable.TableName);
    
        // Insert the data from DataTable to the worksheet starting at cell "A1".
        ws.InsertDataTable(dataTable, "A1", true);
    }
    
    // Save the file to XLS format.
    ef.SaveXls("DataSet.xls");
     
  8. ice123456

    ice123456 New Member

    Joined:
    Dec 15, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    Spire.XLS for .NET also can easily help you deal with this kind of stuff. have a try :charming:
     

Share This Page