java - Writing contents of a JTable to a file -
i cannot seem manage complete functionality. need write out text file.
my jtable populated when query run, query results populate jtable. results users of program have option of writing contents of jtable text file.
the output file have column headings running along top of text file returned query data underneath it.
edit: getting header values added part of code
other writing file, can use following..
stringbuffer buffer = new stringbuffer(); int row,column,header; // write header for(header=0;header<jtable.getcolumncount;header++) { //buffer.append(jtable.getcolumnmodel().getcolumn(header).getheadervalue(); -- not needed buffer.append(jtable.getcolumnname(header); buffer.append(','); } buffer.append('\n'); // write cell data for(row=0;row<jtable.getrowcount();row++) { for(column=0; column< jtable.getcolumncount();column++) { buffer.append(jtable.getmodel().getvalueat(row, column)); buffer.append(','); } buffer.append('\n'); } // write buffer file
Comments
Post a Comment