Aspose. Cells small instance

Source: Internet
Author: User
Aspose. cells. Workbook workbook = new aspose. cells. Workbook ();
Aspose. cells. worksheet sheet = Workbook. worksheets [0];
Sheet. freezepanes (1, 1, 1, 0); // freeze the first line

Sheet. cells ["A1"]. putvalue ("ID ");
Sheet. cells ["B1"]. putvalue ("mobile phone number ");
Sheet. cells ["C1"]. putvalue ("name ");
Sheet. cells ["d1"]. putvalue ("Date of Birth ");
Sheet. cells ["E1"]. putvalue ("gender ");
Sheet. cells ["f1"]. putvalue ("order quantity ");
Sheet. cells ["g1"]. putvalue ("Operation product ID ");
Sheet. cells ["h1"]. putvalue ("order status ");
Sheet. cells ["I1"]. putvalue ("Order success time ");
Sheet. cells ["J1"]. putvalue ("Batch ID ");
Sheet. cells ["K1"]. putvalue ("Payment Method ");
Sheet. cells ["L1"]. putvalue ("errorCode");

/// Todo
/// Set column 1 as text, because this column is full of numbers and is very long, and will become a natural number if it is not processed.
/// Note that styleflag is a set style, and styleflag is a switch. Even if you set the style, it is useless if you do not enable the corresponding styleflag.
Aspose. cells. Style SC1 = Workbook. styles [Workbook. Styles. Add ()];
Sc1.shrinktofit = true;
Sc1.number = 49;

Aspose. cells. styleflag scf1 = new aspose. cells. styleflag ();
Scf1.shrinktofit = true;
Scf1.numberformat = true;
Aspose. cells. Column colomn1 = sheet. cells. Columns [1];
Colomn1.applystyle (SC1, scf1 );

Dt = getdatatable (); // get the datatable
Sheet. cells. importable (DT, false, "A2"); // fill data from A2
Sheet. autofitcolumns (); // adaptive width of each column, which is useful.
Workbook. Save (filename, aspose. cells. fileformattype. excel2007xlsx, aspose. cells. savetype. openinexcel, response); // output

Most of the time, the sorting or display column of the output data is not necessarily the same as the column sorting data obtained by the datatable, so we can simply process it:
For example

Reference content // todo
/// Set column 1 as text, because this column is full of numbers and is very long, and will become a natural number if it is not processed.
/// Note that styleflag is a set style, and styleflag is a switch. Even if you set the style, it is useless if you do not enable the corresponding styleflag.
Aspose. cells. Style SC1 = Workbook. styles [Workbook. Styles. Add ()];
Sc1.shrinktofit = true;
Sc1.number = 49;

Aspose. cells. styleflag scf1 = new aspose. cells. styleflag ();
Scf1.shrinktofit = true;
Scf1.numberformat = true;
Aspose. cells. Column colomn1 = sheet. cells. Columns [1];
Colomn1.applystyle (SC1, scf1 );

Dt = getdatatable (); // get the datatable

Replace:

Reference content datatable dt1 = getdatatable ();
For (INT I = 0; I <dt1.rows. Count; I ++)
{
Sheet. cells [(I + 1), 0]. putvalue (dt1.rows [I] ["create_time"]. tostring ());
Sheet. cells [(I + 1), 1]. putvalue (dt1.rows [I] ["holder_mobile"]. tostring ());
Sheet. cells [(I + 1), 2]. putvalue (dt1.rows [I] ["rec_name"]. tostring ());
Sheet. cells [(I + 1), 3]. putvalue (string. isnullorempty (dt1.rows [I] ["rec_sex"]. tostring ())? "": (Dt1.rows [I] ["rec_sex"]. tostring () = "1 ")? "Male": "female ");
Sheet. cells [(I + 1), 4]. putvalue (dt1.rows [I] ["rec_birthday"]. tostring ());
Sheet. cells [(I + 1), 5]. putvalue (dt1.rows [I] ["base_product_code"]. tostring ());
Sheet. cells [(I + 1), 6]. putvalue (dt1.rows [I] ["sell_price"]. tostring ());
Sheet. cells [(I + 1), 7]. putvalue (dt1.rows [I] ["pay_count"]. tostring ());
Sheet. cells [(I + 1), 8]. putvalue (dt1.rows [I] ["ins_policy"]. tostring ());
Sheet. cells [(I + 1), 9]. putvalue (dt1.rows [I] ["ins_end_date"]. tostring ());
Sheet. cells [(I + 1), 10]. putvalue (rondi. insu. management. utility. stateenum. orderfrom (dt1.rows [I] ["order_from"]. tostring ()));
Sheet. cells [(I + 1), 11]. putvalue (rondi. insu. management. utility. stateenum. orderstate (dt1.rows [I] ["order_state"]. tostring ()));
}

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.