通过 java 代理导出 excel
通过代理导出数据到 Excel 其实很简单,只要输出的时候指定了 MIME 格式为 application/vnd.ms-excel 就行了,每个元素
之间用 TAB 隔开(" "),输出的内容就是用 Excel 打开的。话不多说,直接贴一段代码上来!
import java.io.PrintWriter;
import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Database;
import lotus.domino.NotesException;
import lotus.domino.Session;
import lotus.domino.View;
import lotus.domino.Document;
import java.util.Vector;
/**
* 将视图数据导出到 excel 中
* @author Windindream
*
*/
public class OutputToExcel extends AgentBase {
private Session session = null;
private AgentContext agentContext = null;
private Database db = null;
private View view = null;
private PrintWriter pw = null;
private StringBuilder sb = null;
/* 字段名称(在数据库中的名称) */
private static String[] FIELDS = { "fldYM", "fldBH", "Subject", "AppDate",
"Creator", "Total" };
/* 字段标签 */
private static String[] FIELDSNAME = { "单号-1", "单号-2", "标题", "创建时间", "作者",
"金额" };
public void NotesMain() {
try {
session = getSession();
agentContext = session.getAgentContext();
db = agentContext.getCurrentDatabase();
view = db.getView("Documents.vw");
pw = getAgentOutput();
sb = new StringBuilder();
pw.println("Content-Type:application/vnd.ms-excel");
printHead();
printView();
pw.print(sb.toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
recycle();
}
}