• Post Reply Bookmark Topic Watch Topic
  • New Topic

file formatter for excel

 
belle springfield
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i have a code sniplet here, which converts file to CSV.
can you please help me out on how to modify the code to make the file
converts to XML?


public class ff {

public ff() {
}

public static void formatToCSV(ResultSet rset, File file)
throws FileNotFoundException, SQLException, IOException {
FileOutputStream out = new FileOutputStream(file);

StringBuffer s;
int nCols = rset.getMetaData().getColumnCount();

while (rset.next()) {
s = new StringBuffer();
for (int i = 1; i <= nCols; i++) {
s.append(rset.getString(i));
if (i < nCols)
s.append(',');
else
s.append('\n');
}

out.write(s.toString().getBytes());
}
}

public static void formatToCSV(ResultSet rset, OutputStream out)
throws SQLException {

PrintWriter pw = new PrintWriter(out);

StringBuffer s;
int nCols = rset.getMetaData().getColumnCount();

while (rset.next()) {
for (int i = 1; i <= nCols; i++) {
pw.print(rset.getString(i));
if (i < nCols)
pw.print(',');
else
pw.println();
}
}
}

}

Many thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!