Set the Excel cell format in C #

Source: Internet
Author: User

1Automatic full table column width

Mysheet. cells. Select ();

Mysheet. cells. Columns. autofit ();

 2, Merge

Excelrangeparm. Merge (missing. value );

 3, Bold settings

Excelrangeparm. Font. Bold = true;

 4Font size settings

Excelrangeparm. Font. size = 12;

 5Horizontal Alignment settings

Excelrangeparm. horizontalalignment = excel. xlhalign. xlhaligncenter;

 6Vertical Alignment settings

Excelrangeparm. verticalalignment = excel. xlvalign. xlvaligncenter;

 7, Formula settings

Excelrangeparm. formular1c1 = formula;

 8, Column width settings

Excelrange. columnwidth = width;

 9, Row Height

Excelrange. rowheight = row height;

10, Set the column format

Excel. Range myrange = mysheet. get_range (mysheet. cells [], mysheet. cells []);

 11, Text format

Myrange. numberformatlocal = "@";

 12General Format

Style. numberformatlocal = "[dbnum2] [$-804] g/common format ";

Or

Range. numberformatlocal = "g/common format ";

Xlsheet. cells [1, 1] = "'' + txtkey. text;

 13, Add rows

(Excel. Range) mysheet. cells [15, 3]). entirerow. insert (0 );

 14, Set10Behavior red

Mysheet. get_range (Excel. Range) mysheet. cells [10,200], (Excel. Range) mysheet. cells []). Select ();

Mysheet. get_range (Excel. Range) mysheet. cells [10,200], (Excel. Range) mysheet. cells []). Interior. colorindex = 3;

15, Automatic cell line feed

Myrange. wraptext = true;

16, Automatic adjustment of cell Row Height

Myrange. entirerow. autofit ();


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.