JDataGrid普通文件格式的导入和导出
支持导入和导出多种文件格式,包括csv, html, txt.
CSV格式
CSV格式, 冒号分割的文件格式, 适合多种的数据库和应用程序.
ModelIO能够输出csv格式.
例子代码:
// import csv model
File f = new File("tmp.csv");
Map map = new HashMap(1);
map.put(ModelIO.ENABLE_LOOSE_FORMAT, Boolean.TRUE);
TableModel model = ModelIO.readTableModel(f, "csv", map)
// export csv model
File f = new File("tmp.csv");
Map map = new HashMap(1);
map.put(ModelIO.ENABLE_LOOSE_FORMAT, Boolean.TRUE);
TableModel model = createTableModel();
ModelIO.writeTableModel(model, "csv", map, f);
|
TAB分割的格式
ModelIO能导入和导出TAB分割的格式.
例子代码:
// import csv model
File f = new File("tmp.txt");
Map map = new HashMap(1);
map.put(ModelIO.ENABLE_LOOSE_FORMAT, Boolean.TRUE);
TableModel model = ModelIO.readTableModel(f, "txt", map)
// export txt model
File f = new File("tmp.txt");
Map map = new HashMap(1);
map.put(ModelIO.ENABLE_LOOSE_FORMAT, Boolean.TRUE);
TableModel model = createTableModel();
ModelIO.writeTableModel(model, "txt", map, f);
|
HTML格式
ModelIO能导入和导出Web页格式.
将TableModel发布为Web也格式是很有用的.
例子代码:
// import csv model
File f = new File("tmp.html");
TableModel model = ModelIO.readTableModel(f, "html", null)
// export html model
File f = new File("tmp.html");
ModelIO.writeTableModel(model, "html", null, f);
|