Public void writer_excel (String ssheetname,int irow,string scolumn,string data) { InputStream is=null; OutputStream os=null; iRow=iRow-1; try{ is=new fileinputstream (file); workbook=new Hssfworkbook (is); sheet sheet= Workbook.getsheet (Ssheetname); int column=excel_returncolumnindex (Sheet,irow,scolumn); cell cell=sheet.getrow (IRow). Getcell (Column); system.out.println (Getcellvalue (cell)); cell.setcelltype (cell. cell_type_string); cell.setcellvalue (Data); os=new fileoutputstream (file); workbook.write (OS); }catch (exception e) { e.printstacktrace (); }finally{ try { &nBsp; os.close (); } catch (IOEXCEPTION E1) { // TODO auto-generated catch block e1.printstacktrace (); } try { is.close (); } catch (ioexception e) { // todo auto-generated catch block E.printstacktrace (); } try { workbook.close (); } catch (ioexception e) { // TODO Auto-generated catch block e.printstacktrace (); } } }
Online search for a long time, found that everyone is using POI directly create files, format, font, and write files. However, you always do not see how to modify the file after saving.
According to the way to create a file to modify the file, without saving, the code will only modify the memory of the copy, and will not modify the physical files, you need to write a bit!
The code is as follows:
This is the code that was written. File is a Document object
Os=new fileoutputstream (file); Workbook.write (OS);
Save after using POI to modify Excel