3.5 using Npoi to manipulate excel--to use Excel Chart skillfully

Source: Internet
Author: User

In Npoi, it does not natively support the creation of advanced objects such as charts, but with the help of the L-template, you can use Excel's powerful perspective and charting capabilities in the following example.

First create the template file, define two columns, and the name "sales" that points to this area:

Create a data table where the data source fills in the area you just defined:

The last generated PivotTable report has the following style: Sheet.

So far, the template has been built and saved as "D:\MyProject\NPOIDemo\Chart\Book2.xls". We found that the template is the equivalent of an "empty shelf", there is no way to operate without any data. Next, we fill in the data in this "empty shelf". We write the data in this "empty shelf" by the following code:

StaticvoidMain (String[] args)
{
Hssfworkbook WB=NewHssfworkbook (NewFileStream (@"D:\MyProject\NPOIDemo\Chart\Book2.xls", FileMode.Open));

Hssfsheet Sheet1=Wb. Getsheet ("Sheet1");

Hssfrow row=Sheet1. CreateRow (1);
Row. Createcell (0). Setcellvalue ("Make the Fox rush");
Row. Createcell (1). Setcellvalue (50000);

Row=Sheet1. CreateRow (2);
Row. Createcell (0). Setcellvalue ("Ren Ying");
Row. Createcell (1). Setcellvalue (30000);

Row=Sheet1. CreateRow (3);
Row. Createcell (0). Setcellvalue ("Wind");
Row. Createcell (1). Setcellvalue (80000);

Row=Sheet1. CreateRow (4);
Row. Createcell (0). Setcellvalue ("Let me do it.");
Row. Createcell (1). Setcellvalue (20000
    //write the  Stream data of workbook to the root directory
    filestream file  = new filestream (@ "test.xls ", filemode.create);
    WB. Write (file);
    file. Close ();
}

Open the generated Test.xls file and find that the data has been filled in:

Looking at the pivot table again, there are data:

Summarize:
Excel has a powerful report perspective and charting capabilities, and is easy to use, using Npoi to make the most of it. It is very useful to make graphical reports and pivot reports!

Excel Learning Tutorial: http://www.cnblogs.com/atao/archive/2009/10/25/1589606.html

3.5 using Npoi to manipulate excel--to use Excel Chart skillfully

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.