.net中生成excel后调整宽度

 生成excel后加上

   _Worksheet ActiveSheet;
        //_Chart ActiveChart;
        _Workbook oBook;
        _Application oExcel = new ApplicationClass();
        oExcel.Visible = false;
        oExcel.DisplayAlerts = false;
        oExcel.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow;
        oExcel.AlertBeforeOverwriting = false;
        oExcel.AskToUpdateLinks = false;

        oBook = oExcel.Workbooks.Open(Server.MapPath(xlsUrl), Type.Missing, Type.Missing, Type.Missing, Type.Missing
            , Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
            , Type.Missing, Type.Missing, Type.Missing);

        //这里会报一个错, 解决不了, 先这样应付一下吧.
        System.Threading.Thread.Sleep(500);
  ActiveSheet = (_Worksheet)oBook.ActiveSheet;
  ActiveSheet.ListObjects.AddEx(XlListObjectSourceType.xlSrcRange, ActiveSheet.UsedRange, Type.Missing, XlYesNoGuess.xlYes
            , Type.Missing, "TableStyleMedium2");
  oBook.Save();
  oBook.Close(Type.Missing, Type.Missing, Type.Missing);
  //wb.Close(pnull, pnull, pnull);
        oExcel.Quit();
        //Marshal.ReleaseComObject(ActiveSheet);
        //Marshal.ReleaseComObject(oBook);
        //Marshal.ReleaseComObject(oExcel);

上一篇:Linux搭建gitlab


下一篇:C#实现的三种方式实现模拟键盘按键