A certain version of the POI associated jar package used must be the same ...
The jar pack that Maven uses
<dependency>
<groupId>org.apache.poi</groupId>
<artifactid>poi</artifactid >
<version>3.9</version>
</dependency>
<dependency>
<groupId> org.apache.poi</groupid>
<artifactId>poi-ooxml</artifactId>
<version>3.9</ Version>
</dependency>
private void Exportexcel (List orderlist) {
if (orderlist = null | | orderlist.size () = 0) {
return;
}
try {
String[] Header = {"Order number", "Transaction type", "Unit Price", "Transaction Quantity", "Transaction Amount", "Transaction Time"};
Sxssfworkbook Sxssfworkbook = Createsxssfworkbook (orderlist, header);
//write output
FileOutputStream out = new FileOutputStream ("d://Order statistics. xlsx");
Sxssfworkbook.write (out);
Out.close ();
} catch (Exception e) {
E.printstacktrace ();
}
}
Private Sxssfworkbook Createsxssfworkbook (list<usdtordermodel> dataList, string[] header) {Sxssfworkboo
K Sxssfworkbook = new Sxssfworkbook (500);
Sheet Sheet = null;
row row = null;
int max_row = 500;
int count = 0; if (dataList!= null &&!datalist.isempty ()) {for (Usdtordermodel model:datalist) {if (cou NT% Max_row = 0) {sheet = Sxssfworkbook.createsheet ("Transaction Details _" + (Count/max_row)
);
Create a new row and add several cells.
row = Sheet.createrow (0); Create a cell, set the cell's value for (int i = 0; i < header.length; i++) {Row.createcell (i). setc
Ellvalue (Header[i]);
} row = Sheet.createrow (count% max_row + 1);
Row.createcell (0). Setcellvalue (Model.getorderid ());
Row.createcell (1). Setcellvalue (Model.getordertype ()); Row.createcell (2). Setcellvalue (Model.gettransactionprice ());
Row.createcell (3). Setcellvalue (Model.getdealcount ());
Row.createcell (4). Setcellvalue (Model.gettransactiontotalamount ());
Row.createcell (5). Setcellvalue (Model.gettransactiontime ());
count++;
} else {//Create a default header row if Excel cannot open sheet = Sxssfworkbook.createsheet ("Transaction Details") if it is not created when the list is empty
row = Sheet.createrow (0);
for (int i = 0; i < header.length i++) {Row.createcell (i) setcellvalue (header[i));
} return Sxssfworkbook;
}