C#掌握Excel Sheet使其自順應頁寬與列寬的辦法。本站提示廣大學習愛好者:(C#掌握Excel Sheet使其自順應頁寬與列寬的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#掌握Excel Sheet使其自順應頁寬與列寬的辦法正文
本文實例講述了C#掌握Excel Sheet使其自順應頁寬與列寬的辦法。分享給年夜家供年夜家參考,詳細以下:
///// <summary> /// 1.Clear CircleReference /// 2.Set Page to Fit Wide /// 3.Set Column Text fit /// </summary> /// <param name="app"></param> /// <param name="ws"></param> private void WorkSheetPageSet(Microsoft.Office.Interop.Excel.Application app, Worksheet ws) { ClearCircleReference(ws); SetPagetoFitWide(ws); SetColumnFit(ws); } ///// <summary> /// Set Column Text fit /// </summary> /// <param name="sheet"></param> private static void SetColumnFit(Worksheet sheet) { char column = 'B'; for (int i = 0; i < 25; i++) { Range range = sheet.get_Range(String.Format("{0}1", column.ToString()), String.Format("{0}1", column.ToString())); if (range != null) { range.EntireColumn.AutoFit(); } column++; } } ///// <summary> /// Clear CircleReference /// </summary> /// <param name="sheet">Worksheet object</param> private void ClearCircleReference(Worksheet sheet) { Range range = sheet.CircularReference; while (range != null) { range.Clear(); range = sheet.CircularReference; } } ///// <summary> /// Set Page to Fit Wide /// </summary> /// <param name="ws">Worksheet object</param> private static void SetPagetoFitWide(Worksheet ws) { ws.PageSetup.Zoom = false; ws.PageSetup.FitToPagesWide = 1; ws.PageSetup.FitToPagesTall = false; }
願望本文所述對年夜家C#法式設計有所贊助。