java - Apache POI - Iterating over columns in excel (XSSF) -
this question has answer here:
i want program read excel column top bottom, not left right, doing right now. unfortunately, cannot find in documentation lets me this.
i have excel file looks this:
col1 col2 col3 col4 ----------------------------- row1 | 2,3,1 _ 1 w row2 | 3,2,7 _ 2 x row3 | _ _ 3 y row4 | 4,9 _ 4 z
i'm writing values (using xlwt) in column 2 this:
col1 col2 col3 col4 ----------------------------- row1 | 2,3,1 x,y,w 1 w row2 | 3,2,7 y,x 2 x row3 | _ _ 3 y row4 | 4,9 z 4 z
essentially, column 3 , column 1 being compared, , if cell (1,1) has values matched in column 3, column 4's values (which correspond column 3) written column 2.
i've done in python actually, , considered using jython, however, couldn't find docs on importing python modules jython code. believe xssf apache-poi way can deal xlsx files in java.
relevant page: how cell iteration of excel in java
import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.*; public class expy { public static void main(string[] args) { try { fileinputstream file = new fileinputstream(new file("c:\\users\\...\\bioactives25s.xlsx")); xssfworkbook workbook = new xssfworkbook(file); xssfsheet worksheet = workbook.getsheetat(0); (int rowindex = 0; rowindex<3; rowindex++){ xssfrow row = worksheet.getrow(rowindex); (int columnindex = 0; columnindex<3; columnindex++){ xssfcell cell = row.getcell(columnindex); system.out.print(cell);.getcell(j); //iterates on cells
again, looking way iterate through column values (top bottom). looked through documentation: http://poi.apache.org/spreadsheet/quick-guide.html#iterator
but find code dealing rows , cells, not columns. i'd iterate through columns though. there code deal this?
you can pretty using current api :
for (int columnindex = 0; columnindex<3; columnindex++){ (int rowindex = 0; rowindex<3; rowindex++){ xssfcell cell = worksheet.getrow(rowindex).getcell(columnindex); } }
Comments
Post a Comment