programing

MS Office가 설치되지 않은 컴퓨터에서 Microsoft.Office.Interop.Excel을 사용하는 방법은 무엇입니까?

nasanasas 2020. 11. 12. 08:20
반응형

MS Office가 설치되지 않은 컴퓨터에서 Microsoft.Office.Interop.Excel을 사용하는 방법은 무엇입니까?


Excel 파일로 작동하는 응용 프로그램을 작성 중입니다. 시트를 삭제하는 기능이 필요합니다. Microsoft.Office.Interop.Excel.dll 어셈블리를 사용해야합니다.

개발자 컴퓨터에서 잘 실행되고 있지만 서버에 배포하려고하면 오류가 발생합니다.

파일 또는 어셈블리 'office, Version = 14.0.0.0, Culture = neutral, PublicKeyToken = 71e9bce111e9429c'또는 해당 종속성 중 하나를로드 할 수 없습니다.

MS Office가 컴퓨터에 설치되어 있지 않을 때 문제가 발생한다는 것을 알고 있습니다. 고객은 가격이 아닌 서버에 MS Office를 설치하고 구입하는 것을 원하지 않습니다.

http://forums.asp.net/t/1530230.aspx/1에서 권장하는대로 개발자 컴퓨터에 "Redistributable Primary Interop Assemblies"를 설치 하고 프로젝트를 다시 컴파일합니다.

코드 샘플 :

public bool DeleteSheet(string tableName)
{
    Excel.Application app = null;
    Excel.Workbooks wbks = null;
    Excel._Workbook _wbk = null;
    Excel.Sheets shs = null;

    bool found = false;

    try
    {
        app = new Excel.Application();
        app.Visible = false;
        app.DisplayAlerts = false;
        app.AlertBeforeOverwriting = false;

        wbks = app.Workbooks;
        _wbk = wbks.Add(xlsfile);
        shs = _wbk.Sheets;
        int nSheets = shs.Count;

        for (int i = 1; i <= nSheets; i++)
        {
            Excel._Worksheet _iSheet = (Excel._Worksheet)shs.get_Item(i);
            if (_iSheet.Name == tableName)
            {
                _iSheet.Delete();
                found = true;

                Marshal.ReleaseComObject(_iSheet);
                break;
            }
            Marshal.ReleaseComObject(_iSheet);
        }

        if (!found)
            throw new Exception(string.Format("Table \"{0}\" was't found", tableName));

        _wbk.SaveAs(connect, _wbk.FileFormat, Missing.Value, Missing.Value, Missing.Value,
        Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
        Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
    }
    finally
    {
        _wbk.Close(null, null, null);
        wbks.Close();
        app.Quit();

        Marshal.ReleaseComObject(shs);
        Marshal.ReleaseComObject(_wbk);
        Marshal.ReleaseComObject(wbks);
        Marshal.ReleaseComObject(app);
    }
    return true;
}

예외

다음 오류로 인해 CLSID가 {00024500-0000-0000-C000-000000000046} 인 구성 요소에 대한 COM 클래스 팩토리를 검색하지 못했습니다. 80040154 클래스가 등록되지 않았습니다 (HRESULT 예외 : 0x80040154 (REGDB_E_CLASSNOTREG)).

라인에서 발생

app = new Excel.Application();

누구든지이 기능을 성공적으로 작동시키는 방법에 대해 조언 할 수 있습니까?


MS Office를 설치하지 않으면 Microsoft.Office.Interop.Excel을 사용할 수 없습니다.

Google에서 xls 또는 xlsx를 수정할 수있는 일부 라이브러리를 검색하면됩니다.


If the "Customer don't want to install and buy MS Office on a server not at any price", then you cannot use Excel ... But I cannot get the trick: it's all about one basic Office licence which costs something like 150 USD ... And I guess that spending time finding an alternative will cost by far more than this amount!


you can create a service and generate excel on server and then allow clients download excel. cos buying excel license for 1000 ppl, it is better to have one license for server.

hope that helps.


Look for GSpread.NET. You can work with Google Spreadsheets by using API from Microsoft Excel. You don't need to rewrite old code with the new Google API usage. Just add a few row:

Set objExcel = CreateObject("GSpreadCOM.Application");

app.MailLogon(Name, ClientIdAndSecret, ScriptId);

It's an OpenSource project and it doesn't require Office to be installed.

The documentation available over here http://scand.com/products/gspread/index.html

참고URL : https://stackoverflow.com/questions/11448197/how-to-use-microsoft-office-interop-excel-on-a-machine-without-installed-ms-offi

반응형