2017-09-29 3 views
1

엑셀 파일을 열어 시트 번호를 계산할 때 System.DllNotFoundException이 표시됩니다. 문제의 DLL은 ole32.dll입니다. 온라인이 dll은 Windows와 관련이 있다고 읽었지 만 MacOS 용 Visual Studio Comunity에서 작업합니다. 이 문제를 어떻게 해결할 수 있습니까? Excel 파일을 열려고 할 때 예외가 발생했습니다.

코드입니다 :

using System; 
using System.IO; 
using Microsoft.Office.Interop.Excel; 
using Excel = Microsoft.Office.Interop.Excel; 

namespace Itec 
{ 
    class MainClass 
    { 
     public static int countSheet(string file){ 

      int numSheet = 1; 

      Application excelApp = new Application(); 
      Workbook workBook = excelApp.Workbooks.Open("d:/Book1.xls"); 

      numSheet = workBook.Sheets.Count; 

      return numSheet; 
     } 

     public static void Main(string[] args) 
     { 
      string user, fileName, pathFile, ext; 

      do 
      { 
       user = System.Security.Principal.WindowsIdentity.GetCurrent().Name; 

       Console.WriteLine("Inserire il nome del file (se è in una cartella scrivere nel seguente formato \"nomeCartella/nomeFile.pdf\"): "); 
       fileName = Console.ReadLine(); 
       pathFile = "/Users/" + user + "/Desktop/" + fileName; 
       ext  = Path.GetExtension(pathFile); 

       if (String.Equals(ext, ".xlsx")) 
       { 
        if (File.Exists(pathFile)) 
        { 
         countSheet(pathFile); 
        } 
        else 
        { 
         Console.WriteLine("Il file inserito non esiste"); 
         Console.WriteLine("Premere invio per riprovare"); 
         Console.ReadKey(); 
        } 
       } 
       else 
       { 
        Console.WriteLine("Estensione non corretta"); 
        Console.WriteLine("Premere invio per riprovare"); 
        Console.ReadKey(); 
       } 

      } 
      while (!String.Equals(ext, ".xlsx") && !File.Exists(pathFile)); 
     } 
    } 
} 
+2

해결하려면 Mac OS X 대신 Windows를 사용하십시오. 또는 플랫폼에 구애받지 않는 Excel 라이브러리를 사용하십시오. _Maybe_ [EPPlus] (https://github.com/JanKallman/EPPlus) ist one. –

+0

먼저 appliation에서 에러를 피하기 위해'try {} catch (Excetpion) {}'을 사용하십시오. –

+0

@ FelixD. 'try {} catch (Excetpion) {}'을 사용하지만 명령을 건너 뛰어도 문제가 해결되지 않습니다. – th3g3ntl3man

답변

1

불행하게도 Microsoft.Office.Interop.Excelthis Github의 문제에 명시된 바와 같이, Mac 또는 Linux에서 작동하지 않습니다

우리는 사무실 COM API를 작업을 할 계획이 없습니다 Mac 또는 Linux에서. Office 팀이이를 수행하는 방법에 대한 문서를 작성하면 기꺼이 살펴 보겠습니다. 그 결과로 결산.

대안으로 나는 EPPlus을 사용하도록 권장합니다.

관련 문제