【发布时间】:2013-02-14 10:12:41
【问题描述】:
我试图将 CSV 文件转换为 JSON 格式,但我不知道 ANT 或 MAVEN。我使用过 Apache POI。我正在尝试使用 Apache POI 来做到这一点。有没有其他方法可以做到这一点?
这就是我试图做的,但得到以下错误 --java.lang.ClassNotFoundException: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet
// 开始构造 JSON。
JSONObject json = new JSONObject();
JSONArray rows=new JSONArray();
for ( Iterator<org.apache.poi.ss.usermodel.Row> rowsIT = sheet.rowIterator(); rowsIT.hasNext(); )
{
org.apache.poi.ss.usermodel.Row row = rowsIT.next();
JSONObject jRow = new JSONObject();
// Iterate through the cells.
JSONArray cells = new JSONArray();
for ( Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext(); )
{
Cell cell = cellsIT.next();
cells.put( cell.getStringCellValue() );
}
jRow.put( "cell", cells );
rows.put( jRow );
}
【问题讨论】:
-
是的,还有另一种方法可以做到这一点。问题已回答。
-
请发布您的 CSV 标头,我为您制作了二十行代码...
标签: java javascript json apache-poi