Import org. Apache. Poi. hssf. usermodel .*;
Import org. Apache. Poi. hssf. util .*;
Import org. Apache. Poi. hssf. usermodel .*;
Import org. Apache. Poi. poifs. filesystem. poifsfilesystem;
Import java. Io. fileinputstream;
Import java. Io. filenotfoundexception;
Import java. Io. fileoutputstream;
Import java. Io. ioexception;
/**
* Test the poi Processing Formula.
*
* Problem description: After data is imported through poi, the original formula cells that reference the imported data cannot be displayed. You need to locate the formula unit again.
* The result is obtained after the formula is transferred again.
*
* Solution: Set the formula again for the formula cell.
*
* Related Files: manually set cell b2 = C2 + D2 in the test.xls File
*
*/
Private Static void readset (string filename ){
Poifsfilesystem FS;
Try {
FS = new poifsfilesystem (New fileinputstream (filename ));
Hssfworkbook WB = new hssfworkbook (FS );
Hssfsheet sheet = WB. getsheet ("sheet1 ");
Hssfrow ROW = sheet. getrow (short) 1 );
Hssfcell cell = row. getcell (short) 2 );
Cell. setcellvalue (short) 5 );
Cell = row. getcell (short) 3 );
Cell. setcellvalue (short) 40 );
Hssfcell cell1 = row. getcell (short) 1 );
If (hssfcell. cell_type_formula = cell1.getcelltype ()){
// Obtain the formula cell formula and reset it.
Cell1.setcellformula (cell1.getcellformula ());
}
Fileoutputstream fileout = new fileoutputstream (filename );
WB. Write (fileout );
Fileout. Close ();
}
Catch (ioexception e ){
E. printstacktrace ();
}
}
Public static void ylb (string ym ){
System. Out. println ("Poi ");
// Createfile ("C:/test.xls ");
Createsheet ("C:/gisoracle.xls ");
Readset ("C:/test.xls ");
System. Out. println ("================ ");
}
Reference: http://gohands.5d6d.com/redirect.php? Tid = 197 & goto = lastpost