![](/img/trans.png)
[英]A dialog box comes when I try to open excel file with .xls as extension
[英]Exception when I try to open an Excel file
當我嘗試打開一個 excel 文件來計算她的工作表編號時,我得到一個System.DllNotFoundException
。 有問題的 dll 是ole32.dll
。 我在網上讀到這個 dll 是相對於 Windows 的,但我使用 Visual Studio 社區 for MacOS。 我該如何解決這個問題?
這是代碼:
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));
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.