public static Model.BoardChargeList DeSerializeBoardCharge(string fileName)
            {
                Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
                Microsoft.Office.Interop.Excel.Sheets sheets;
                Microsoft.Office.Interop.Excel.Workbook workbook1 = null;
                object oMissiong = System.Reflection.Missing.Value;
                try
                {
                    workbook1 = app.Workbooks.Open(fileName, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong);
                    sheets = workbook1.Worksheets;
                    Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);//读取第一张表
                    Microsoft.Office.Interop.Excel.Range range;
                    range = (Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 37];
                    range.Value = "test";
                }
                catch (Exception ex)
                {
                    Controller.MessageConsole.WriteConsole(ex);
                    return null;
                }
                finally
                {
                    workbook1.Save();
                    workbook1.Close(false, oMissiong, oMissiong);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook1);
                    workbook1 = null;
                    app.Workbooks.Close();
                    app.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
                    app = null;
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                Model.BoardChargeList boardList = new Model.BoardChargeList();
                FileStream applyingStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                HSSFWorkbook workbook = new HSSFWorkbook(applyingStream);
                ISheet sheet = workbook.GetSheetAt(0);
                int rowCount = sheet.LastRowNum;
                for (int i = 3; i <= rowCount; i++)
                {
                    IRow row = sheet.GetRow(i);
                    if (row == null) continue; //没有数据的行默认是null
                    Model.BoardCharge board = new Model.BoardCharge();

                    board.ContractNum = row.GetCell(6) == null ? "" : row.GetCell(6).ToString().Replace("'", "").Trim();

                    board.StudentName = row.GetCell(7) == null ? "" : row.GetCell(7).ToString();

                    board.ApplicationType = row.GetCell(8) == null ? "" : row.GetCell(8).ToString();

                    boardList.Add(board);

                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                return boardList;
            }
示例#2
0
 public static Model.BoardChargeList LoadQuan(string[] fileNames)
 {
     Model.BoardChargeList boardList = new Model.BoardChargeList();
     if (fileNames != null && fileNames.Length > 0)
     {
         foreach (string fileName in fileNames)
         {
             Model.DTO.HandleQuantification _quan = Controller.XMLController.LoadXml.LoadQuanXml(fileName);
             if (_quan != null)
             {
                 foreach (Model.DTO.HKHandleQuanDetail item in _quan.HKDetails.Values)
                 {
                     boardList.Add(new Model.BoardCharge() { ApplicationType = item.ApplicationType, ContractNum = item.ContractNum, StudentName = item.StudentName });
                 }
                 foreach (Model.DTO.UKHandleQuanDetail item in _quan.UKDetails.Values)
                 {
                     boardList.Add(new Model.BoardCharge() { ApplicationType = item.ApplicationType, ContractNum = item.ContractNum, StudentName = item.StudentName });
                 }
             }
         }
     }
     return boardList;
 }