public static ExcelAccess GetInstance()
 {
     if (null == excel)
     {
         excel = new ExcelAccess();
     }
     return excel;
 }
 public string ReadXlsRangeValue(string path, int sheetIndex, int rownumber, int colnumber)
 {
     if (!File.Exists(path)) { return ""; }
     Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
     Microsoft.Office.Interop.Excel.Workbooks workbooks = null;
     Microsoft.Office.Interop.Excel.Workbook book = null;
     Excel.Worksheet sheet = null;
     Excel.Range range = null;
     object oV = System.Reflection.Missing.Value;
     try
     {
         // 步骤1:打开某人的表xls
         book = excel.Workbooks.Open(path, oV, oV, oV, oV,
         oV, oV, oV, oV, oV, oV, oV, oV, oV, oV);
         sheet = (Excel.Worksheet)excel.Sheets.get_Item(sheet);
         sheet.Name = "Salary详细";
         excel.Visible = false;
         // 步骤2:读取数据
         range = (Excel.Range)sheet.Cells[rownumber, colnumber];
         string value = range.Value2.ToString();
         // 步骤3:保存表格
         book.Save();
         // 步骤4:关闭book
         excel.Workbooks.Close();
         return value;
     }
     catch (Exception ex)
     {
         return "";
     }
     finally
     {
         System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
         System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
         System.Runtime.InteropServices.Marshal.ReleaseComObject(range);
         System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
         book = null;
         sheet = null;
         range = null;
         excel = null;
         GC.Collect();
     }
 }
Exemple #3
0
        public DataView()
        {
            InitializeComponent();

            #region  初始化分值表结构

            DataColumn dc0 = new DataColumn("personname");
            DataColumn dc1 = new DataColumn("graedu", typeof(System.Double));
            DataColumn dc2 = new DataColumn("graold", typeof(System.Double));
            DataColumn dc3 = new DataColumn("graPermit", typeof(System.Double));
            DataColumn dc4 = new DataColumn("graWordate", typeof(System.Double));
            DataColumn dc5 = new DataColumn("graLevel", typeof(System.Double));
            DataColumn dc6 = new DataColumn("graEnglish", typeof(System.Double));
            DataColumn dc7 = new DataColumn("graCheckbody", typeof(System.Double));
            DataColumn dc8 = new DataColumn("gratrainDuty", typeof(System.Double));
            DataColumn dc9 = new DataColumn("gratrainAboard", typeof(System.Double));
            DataColumn dc10 = new DataColumn("graAdd", typeof(System.Double));
            DataColumn dc12 = new DataColumn("graDuty", typeof(System.Double));
            DataColumn dc11 = new DataColumn("total", typeof(System.Double));
            DataColumn dc13 = new DataColumn("Date", typeof(System.String));
            DataColumn dc14 = new DataColumn("Personid", typeof(System.String));
            DataColumn dc15 = new DataColumn("idcard", typeof(System.String));
            DataColumn dc16 = new DataColumn("CtrlYear", typeof(System.String));
            DataColumn dc17 = new DataColumn("CtrlDuty", typeof(System.Double));
            DataColumn dc18 = new DataColumn("HighPost", typeof(System.Double));
            DataColumn dc19 = new DataColumn("PermitCheck", typeof(System.Double));

            dtScore.Columns.Add(dc0);
            dtScore.Columns.Add(dc1);
            dtScore.Columns.Add(dc2);
            dtScore.Columns.Add(dc3);
            dtScore.Columns.Add(dc4);
            dtScore.Columns.Add(dc5);
            dtScore.Columns.Add(dc6);
            dtScore.Columns.Add(dc7);
            dtScore.Columns.Add(dc8);
            dtScore.Columns.Add(dc9);
            dtScore.Columns.Add(dc10);
            dtScore.Columns.Add(dc11);
            dtScore.Columns.Add(dc12);
            dtScore.Columns.Add(dc13);
            dtScore.Columns.Add(dc14);
            dtScore.Columns.Add(dc15);
            dtScore.Columns.Add(dc16);
            dtScore.Columns.Add(dc17);
            dtScore.Columns.Add(dc18);
            dtScore.Columns.Add(dc19);
            #endregion

            #region 加载标准
            ExcelAccess excel = new ExcelAccess();
            dsCritical = excel.GetExcelData(Application.StartupPath + "\\管制员打分.xls");
            #endregion
        }