zoukankan      html  css  js  c++  java
  • Excel 隐藏Sheet

     private void OpenForEditSheet(string strFilePath, string strSheetName)
        {
            Microsoft.Office.Interop.Excel.ApplicationClass xlApp = new ApplicationClass();
            Microsoft.Office.Interop.Excel.Workbooks xlWorkbooks;
            Microsoft.Office.Interop.Excel.Workbook xlWorkbook;
            Microsoft.Office.Interop.Excel.Worksheet xlWorksheet;
            System.Type tyWorkbooks;
            System.Reflection.MethodInfo[] methods;
            object objFilePath;
            object oMissing = System.Reflection.Missing.Value;
            strFilePath = Server.MapPath(strFilePath);
            if (!System.IO.File.Exists(strFilePath))
            {
                throw new System.IO.FileNotFoundException();
                return;
            }
            try
            {
                xlApp.Visible = true;
                xlWorkbooks = xlApp.Workbooks;
                tyWorkbooks = xlWorkbooks.GetType();
                methods = tyWorkbooks.GetMethods();
                objFilePath = strFilePath;
                object Nothing = System.Reflection.Missing.Value;
                xlWorkbook = xlApp.Workbooks.Open(strFilePath, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
                xlWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkbook.Worksheets[strSheetName];
                foreach (Worksheet sheet in xlWorkbook.Worksheets)
                {
                    sheet.Visible = XlSheetVisibility.xlSheetVisible;
                }
                foreach (Worksheet sheet in xlWorkbook.Worksheets)
                {
                    if (sheet.Name.ToUpper() != strSheetName.ToUpper())
                    {
                        sheet.Visible = XlSheetVisibility.xlSheetHidden;
                        
                    }
                }
                //xlWorksheet.Visible = XlSheetVisibility.xlSheetVisible;
                //xlWorkbook.Close(oMissing, oMissing, oMissing);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //if (xlApp != null)
                //{
                //    xlApp.Quit();
                //    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
                //    xlApp = null;
                //}
                //GC.Collect();
            }
        }
  • 相关阅读:
    [luoguP2486] [SDOI2011]染色(树链剖分)
    [POJ3162]Walking Race(DP + 单调队列)
    [HDU3586]Information Disturbing(DP + 二分)
    [luoguP1280] 尼克的任务(DP)
    [luoguP1282] 多米诺骨牌(DP + 背包)
    AOJ 0558 Cheese【BFS】
    POJ 3009 Curling 2.0【带回溯DFS】
    AOJ 0033 Ball【DFS】
    AOJ 0118 Property Distribution【DFS】
    POJ 1979 Red and Black【DFS】
  • 原文地址:https://www.cnblogs.com/TNTZWC/p/1945136.html
Copyright © 2011-2022 走看看