MongoDB中的架构:
{ “名称”:“ Kamala”, “流量”:[ { “ Date”:“ 2018-08-03”, “ New”:“ set”, “表格”:{ “ y”:“ 1”, “ d”:“ 3” “ p”:“ 3” } } ] }
在Java中
String db = "Database";
String col = "col";
String Host="localhost";
String Port="27017";
String fileName = "D:/File/sample.xls";
String Query = "C:\\Program Files\\MongoDB\\Server\\3.4\\bin\\mongoexport.exe --host " + Host + " --port " + Port + " --db " + db + " --collection " + col + " --type=xls--fields Name,Flows, --out " + fileName + "";
try {
System.out.println(Query);
StringTokenizer st = new StringTokenizer(Query);
String[] Queryarray = new String[st.countTokens()];
for (int i = 0; st.hasMoreTokens(); i++)
Queryarray[i] = st.nextToken();
ProcessBuilder processBuilder = new ProcessBuilder(Queryarray);
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
BufferedReader processOutput = new BufferedReader(new InputStreamReader(process.getInputStream()));
String data = "";
while ((data = processOutput.readLine()) != null) {
System.out.println(data);
}
} catch (Exception e) {
e.printStackTrace();
}
}
我尝试了这段代码,但是整个文档都存储在一个单元格中(在excel中),但是,我试图以这种类型(名称,日期,新建,表格)存储该文档