Nopi uses a template to generate an Excel file

Source: Internet
Author: User

 

Private void btncopy_click (Object sender, eventargs E)
{
Try
{

// Excel template path
Filestream file = new filestream (@ "E:/book1.xls", filemode. Open, fileaccess. Read );

Hssfworkbook = new hssfworkbook (File );
Sheet sheet1 = hssfworkbook. getsheet ("sheet1 ");
// Sheet1.createrow (3). createcell (3). setcellvalue (12345 );
// String value1 = sheet1.getrow (1). getcell (1). tostring ();
// Sheet1.getrow (2). getcell (1). setcellvalue (true );
// Sheet1.getrow (1). getcell (1). setcellvalue ("Chen ");
// Sheet1.getrow (1). getcell (1). setcellvalue ("Sss ");
// Sheet1.getrow (1). getcell (1). setcellvalue ("1111 ");
// Sheet1.getrow (2). getcell (1). setcellvalue (300 );
// Force EXCEL to recalculate all the formula while open
Sheet1.forceformularecalculation = true;

If (file. exists (@ "E:/test.xls "))
{
File. Delete (@ "E:/test.xls ");

}
Else
{
Filestream file2 = new filestream (@ "E:/test.xls", filemode. Create );
Hssfworkbook. Write (file2 );
File2.close ();
}
File. Close ();
MessageBox. Show ("suc ");
}
Catch (exception ex)
{
MessageBox. Show ("Err ");
}
}

Note: 1. If the value in the template is assigned another value: sheet1.getrow (2). getcell (1). setcellvalue (true );

2. If no value is assigned, it is null: sheet1.createrow (3). createcell (3). setcellvalue (12345 );

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.