当前位置:编程学习 > C#/ASP.NET >>

反编译DLL文件错误,提示“无法显示调用运算符或访问器”

反编译了一个第三方DLL文件。编译后出现很多错误提示:“无法显示调用运算符或访问器”。画红框位置都是显示该提示。如下图:


以下是源码:

using Microsoft.Office.Interop.Excel;
using System;
using System.Data;
using System.Runtime.InteropServices;
using System.Web;

namespace CRM.Utility.Tif
{
   
    public class ExportExcel
    {
        public string export(DataSet ds, string path)
        {
            string str = "";
            Application o = new ApplicationClass();
            try
            {
                o.set_DisplayAlerts(false);
                o.set_Visible(false);
                Workbooks workbooks = o.get_Workbooks();
                workbooks.Add(Type.Missing);
                Workbook workbook = o.get_ActiveWorkbook();
                Sheets sheets = workbook.get_Worksheets();
                sheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                Worksheet worksheet = (Worksheet) sheets.Default(1);
                int count = ds.Tables[0].Columns.Count;
                int num2 = 0;
                while (num2 < count)
                {
                    worksheet.get_Cells().set__Default(1, num2 + 1, ds.Tables[0].Columns[num2].Caption.ToString());
                    num2++;
                }
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    for (num2 = 0; num2 < count; num2++)
                    {
                        worksheet.get_Cells().set__Default(i + 2, num2 + 1, ds.Tables[0].Rows[i][num2].ToString());
                    }
                }
                str = HttpContext.Current.Server.MapPath(path) + @"\MyExcel" + HttpContext.Current.Session["UserId"].ToString() + ".xlsx";
                o.set_AlertBeforeOverwriting(false);
                worksheet.SaveAs(str, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                workbook.Close(null, null, null);
                Marshal.ReleaseComObject(worksheet);
                Marshal.ReleaseComObject(sheets);
                Marshal.ReleaseComObject(workbook);
                Marshal.ReleaseComObject(workbooks);
                Marshal.ReleaseComObject(o);
                workbooks = null;
                workbook = null;
                sheets = null;
                worksheet = null;
                GC.Collect();
            }
            finally
            {
                o = null;
            }
            return str;
        }
    }
}
--------------------编程问答-------------------- 百度了一下,说是反编译的软件自动在前面加上了set 或get;但是去掉后,又出现了下面的错误提示:
--------------------编程问答-------------------- 看起来,还不如读懂代码,自己重写呢。 --------------------编程问答-------------------- Workbooks是属性,不是方法。
因此要这样
Workbooks wordbooks = o.Workbooks;

其他的应该一样。 --------------------编程问答-------------------- 反编译程序没有正确处理索引器和属性。

“百度了一下,说是反编译的软件自动在前面加上了set 或get”
错了,不是反编译软件加上的,而是C#编译器在编译的时候实际上把属性编译成get_和set_开头的方法。
--------------------编程问答-------------------- 自己顶一下!!急!
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,