Use C # To control the Excel Sheet to make it adaptive to the page width and column width

Source: Internet
Author: User

1/** // <summary>
2 // 1. Clear CircleReference
3 // 2.Set Page to Fit Wide
4 // 3.Set Column Text fit
5 /// </summary>
6 /// <param name = "app"> </param>
7 // <param name = "ws"> </param>
8 private void WorkSheetPageSet (Microsoft. Office. Interop. Excel. Application app, Worksheet ws)
9 {
10 ClearCircleReference (ws );
11
12 SetPagetoFitWide (ws );
13
14 SetColumnFit (ws );
15}
16
17/** // <summary>
18 // Set Column Text fit
19 /// </summary>
20 /// <param name = "sheet"> </param>
21 private static void SetColumnFit (Worksheet sheet)
22 {
23 char column = B;
24 for (int I = 0; I <25; I ++)
25 {
26
27 Range range = sheet. get_Range (String. Format ("{0} 1", column. ToString ()),
28 String. Format ("{0} 1", column. ToString ()));
29 if (range! = Null)
30 {
31 range. EntireColumn. AutoFit ();
32}
33 column ++;
34}
35}
36
37/*** // <summary>
38 // Clear CircleReference
39 /// </summary>
40 /// <param name = "sheet"> Worksheet object </param>
41 private void javasirclereference (Worksheet sheet)
42 {
43 Range range = sheet. CircularReference;
44 while (range! = Null)
45 {
46 range. Clear ();
47 range = sheet. CircularReference;
48}
49}
50
51/*** // <summary>
52 // Set Page to Fit Wide
53 /// </summary>
54 // <param name = "ws"> Worksheet object </param>
55 private static void SetPagetoFitWide (Worksheet ws)
56 {
57 ws. PageSetup. Zoom = false;
58 ws. PageSetup. FitToPagesWide = 1;
59 ws. PageSetup. FitToPagesTall = false;
60}
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.