9
Answers

Unable to cast COM object of type 'Microsoft.Office.Interop.

moorthy subramani

moorthy subramani

12y
40.3k
1
Hi,
I am getting this error while i export and import the excel file in the office 2003 format.
The error is:
Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
this is the code i wrote,

Microsoft.Office.Interop.Excel.Application objApplication = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook workbook = objApplication.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel.Sheets xlSheets = workbook.Worksheets;
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

Please any one help me for this problem...
Answers (9)
0
Vulpes
NA 98.3k 1.5m 12y
Try this:

import java.io.*;
import java.util.*;

public class Catalin
{
   public static void main(String[] args)
   {
       ArrayList<Integer> sumsList = new ArrayList<Integer>();

       try
       {
          BufferedReader br = new BufferedReader(new FileReader("catalin.txt"));
          String line;

          while ((line = br.readLine()) != null) 
          {
             String[] items = line.split(";");
             int number = Integer.parseInt(items[1]);
             int number2 = Integer.parseInt(items[2]);
             sumsList.add(number + number2);
          }

          br.close();
       }
       catch(IOException e)
       {
          System.out.println("I/O Error : " + e);
       }
       
       // convert ArrayList<Integer> to int[]
       int[] sumsArray = new int[sumsList.size()];
       for(int i = 0; i < sumsArray.length; i++) sumsArray[i] = sumsList.get(i);

       System.out.println("Line Sum");
       System.out.println("---- ---");

       for(int i = 0; i < sumsArray.length; i++)
       { 
          System.out.println((i + 1) + "     " + sumsArray[i]);
       }
   }
}